[postgis-users] writing function using C

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Thu Mar 12 02:48:19 PDT 2009


eehab hamzeh wrote:

> Dear  all,
> 
> 
> 
> I try to compile the code below to  dynamic library, the  problem if i 
> declare the variable type to anything else int32, i recieve the error 
> as  below, any body have experience in writing functions using c
> 
> i use VC++ 6.
> 
> Kind regards
> 
> ihab
> 
> 
> extern "C" {
> Datum add_one(PG_FUNCTION_ARGS) {
>     float8 arg = PG_GETARG_FLOAT8(0);
>  float8 arg1 = PG_GETARG_FLOAT8(1);
> 
>     PG_RETURN_FLOAT8(arg + arg1);
> }


Hi ihab,

As a starting point, you're missing the PG_FUNCTION_INFO_V1(add_one) 
macro at the start of your code, plus a bunch of #includes. I'd suggest 
that you take a look at 
http://www.postgresql.org/docs/8.3/interactive/xfunc-c.html, the PostGIS 
codebase, and ask further questions on the PostgreSQL mailing lists.


HTH,

Mark.

-- 
Mark Cave-Ayland - Senior Technical Architect
PostgreSQL - PostGIS
Sirius Corporation plc - control through freedom
http://www.siriusit.co.uk
t: +44 870 608 0063



More information about the postgis-users mailing list