Re: C++ User-defined functions - Mailing list pgsql-general

From Craig Ringer
Subject Re: C++ User-defined functions
Date
Msg-id 49B55366.6010409@postnewspapers.com.au
Whole thread Raw
In response to C++ User-defined functions  (George Oakman <oakmang@hotmail.com>)
Responses Re: C++ User-defined functions  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: C++ User-defined functions  (George Oakman <oakmang@hotmail.com>)
List pgsql-general
George Oakman wrote:

> I am trying to write a user-defined function in C++. Most examples are give in plain C. I would be very grafeful for
asample program/code-snippet in C++. 

It's just like any other C/C++ code mixing. You must make sure that any
C-only headers are included within an `extern "C"' block, and declare
any functions that'll be accessed via dlopen() etc as 'extern "C"' too.
You may only use POD types, arrays of POD types, and structs of POD
types (with no methods) in calls to/from C code.

In other words, all PostgreSQL must see is plain C code, but your
'extern "C"' functions may call C++ methods and work with C++ objects
internally.

There's lots more information about this on the Internet. Just look for
generic resources on calling C from C++ and vice versa.

(I don't *think* there are any issues with libstdc++, though you'd
probably have to make sure that no other program linked into Pg brings
in a different version of libstdc++.)

--
Craig Ringer

pgsql-general by date:

Previous
From: George Oakman
Date:
Subject: C++ User-defined functions
Next
From: Umar Farooq
Date:
Subject: PostgreSQL Memory Management