Re: C++ User-defined functions

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: George Oakman <oakmang(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: C++ User-defined functions
Date: 2009-03-09 17:35:34
Message-ID: 49B55366.6010409@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 a sample 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-03-09 18:10:47 in role, ownership and permissions was: grant everything on everything and then revoke
Previous Message Umar Farooq 2009-03-09 16:39:47 PostgreSQL Memory Management