Subject: Re: C++

From: [email-masked] (Chris Flatters)
Date: Wed, 8 Jul 92 12:46:51 -0700

> I think there's a way to do this, but it's awfully kludgey.  I
> strongly recommend that you avoid attempting to define functions that
> are not written in C or Postquel.  These are the only languages we
> support.
> 
> If you really want to use C++, try doing the following:
> 
> Compile your function.  Many C++ implementations actually preprocess
> your code and translate it to C.  What you have to do is find out what
> your function has been (re-)named by the C++ preprocessor.  You can do
> this by running 'nm -t' on your object file.  Assuming you have a C++
> method declared as:
> 
> int foobar(char, float),
> 
> nm should hopefully show you some C function name that looks like foobar with
> its signature, i.e. foobar_int_char_float.
> 
> This is the function you should register with Postgres, and you will
> have to invoke *this* function from your Postgres queries, e.g.
> 
> define function foobar_int_char_float
>  (language = "c", returntype = int4)
>  arg is (char, float8) as "/tmp/cplusplus.o"
> 
> retrieve (emp.all)
>    where emp.dno = dept.dno
>      and emp.salary = foobar_int_char_float('a', dept.budget)
> 
> Not very pretty.

And unlikely to work.  In general C++ code that uses class facilities
will require run-time support from libC.a, which is not linked with
POSTGRES.

You should be able to use C++ functions within POSTGRES if

1 - you do not use class facilities and avoid the use of new/delete; and

2 - you declare the functions visible to POSTGRES using extern "C"
(eg. extern "C" int foobar(char, float);) so that they have C-style
linkage (ie. their names are not mangled).

If you don't follow these rules all bets are off.

	Chris Flatters
	[email-masked]