Re: calling C++ functions from PostgreSQL

From: Antti Haapala <antti(dot)haapala(at)iki(dot)fi>
To: John Gunther <inbox(at)bucksvsbytes(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: calling C++ functions from PostgreSQL
Date: 2003-04-07 15:01:33
Message-ID: Pine.GSO.4.44.0304071735050.3279-100000@paju.oulu.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


On Mon, 7 Apr 2003, John Gunther wrote:

> The PostgreSQL Programmer's Guide, Section 9.5, says "User-defined
> functions can be written in C (or a language that can be made compatible
> with C, such as C++)". Can someone point me to some examples or docs on
> how to make C++ compatible with C? Despite searching, I'm unable to find
> anything comprehensive that discusses calling C++ functions from C
> programs.

Didn't find any good tuts about this... so here goes:

You can't call functions with C++ linkage from C programs. The keyword you
are missing is extern "C", which causes C programs to be compiled with C
linkage.

You can prefix prototypes and/or actual function definitions in C++
program with extern "C", or you can surround many of them in a block
(extern "C" { ... }).

Remember, that you probably can't use C++ library functions/classes etc in
PostgreSQL though.

--
Antti Haapala
+358 50 369 3535

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2003-04-07 15:36:18 Re: Basic info
Previous Message Shaun Jurrens 2003-04-07 14:06:36 operator '~~' for types 'inet' and '"unknown"'