Re: ECPG and C++ compilation

From: "Demetres Pantermalis" <dpant(at)intracom(dot)gr>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: ECPG and C++ compilation
Date: 2003-02-21 08:37:18
Views: Raw Message | Whole Thread | Download mbox
Lists: pgsql-interfaces

Thanks for your reply.

However, I don't think that the problem has to do with C or C++ code (as
source) and as a proof, all of the examples in the test directory compile
without a problem with the C++ compilers, except test2.pgc and test3.pgc
which include VARCHAR definitions (and test4.pgc which has a different
problem - at line 15 text[10] should be changed to text[11]).
The problem is more specific with the generated code from 'ecpg' regarding
this VARCHAR type.

A more detailed investigation on the issue:
The generated code contains the following lines:
#line 20 "test2.pgc"
struct personal_struct {
#line 20 "test2.pgc"
struct varchar_name { int len; char arr[ 8 ]; } name ;

#line 21 "test2.pgc"
birthinfo birth ;
} personal , * p ;

and after some other lines, the 'varchar_name' struct is used to 'fetch'
from the cursor in the following way:
while (1) {
strcpy(msg, "fetch");
{ ECPGdo(__LINE__, NULL, "fetch cur", ECPGt_EOIT,
ECPGt_varchar,&(p->name),8L,1L,sizeof(struct varchar_name),

Everything is OK for C, but for C++ the struct 'varchar_name' is considered
an incomplete type and therefore the sizeof(struct varchar_name) produces
the error. Replacing sizeof(struct varchar_name) with a constant value (ie
4(for len)+8(for arr) =12) then the compilation with the C++ compiler is
I've run some tests with Oracle's ESQL preprocessor just to see what is
produced. Oracle does something similar but seems to calculate the sizeof
the structure and uses this value instead of sizeof(struct ...).

Another solution is to 'typedef' the varchar_name structure, before the
definition of the personal_struct (ie typedef struct varchar_name { int len;
char arr[ 8 ]; } varchar_name;) and then use 'varchar_name name;' inside
the personal_struct (...but this means post-process the pre-processor's
output!!! ).

Any comments appreciated...


-----Original Message-----
From: Peter Eisentraut [mailto:peter_e(at)gmx(dot)net]
Sent: Thursday, February 20, 2003 7:16 PM
To: Demetres Pantermalis
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] ECPG and C++ compilation

Demetres Pantermalis writes:

> What I get is the following error:
> test2.pgc: In function `int main()':
> test2.pgc:71: `sizeof' applied to incomplete type `varchar_name'
> test2.pgc:101: `sizeof' applied to incomplete type `varchar_name'
> Can anybody suggest a method to overcome this problem?

Use a C compiler to compile C code and a C++ compiler to compile C++ code,
and then link them together if you are so inclined.

Peter Eisentraut peter_e(at)gmx(dot)net

In response to


Browse pgsql-interfaces by date

  From Date Subject
Next Message Emmanuel Charpentier 2003-02-21 19:33:22 Re: PgAdmin problem
Previous Message Michael Meskes 2003-02-21 07:14:29 Re: ECPG include problem