X-Original-To: pgsql-interfaces@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A142A474E5C for ; Sat, 22 Feb 2003 10:14:51 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 63057-06 for ; Sat, 22 Feb 2003 10:14:40 -0500 (EST) Received: from crtntx1-ar11-4-62-011-208.crtntx1.dsl-verizon.net (crtntx1-ar11-4-62-009-178.crtntx1.dsl-verizon.net [4.62.9.178]) by postgresql.org (Postfix) with ESMTP id 42CDC474E4F for ; Sat, 22 Feb 2003 10:14:40 -0500 (EST) Received: from reliant.home.pri (reliant.home.pri [192.168.1.25]) by crtntx1-ar11-4-62-011-208.crtntx1.dsl-verizon.net (Postfix) with ESMTP id 8EB593018 for ; Sat, 22 Feb 2003 09:14:50 -0600 (CST) Subject: Re: ECPG and C++ compilation From: Matthew Vanecek To: Postgresql Interfaces List In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-VjSqap5BxGVJPoJUgvlJ" Organization: Message-Id: <1045926883.27169.76.camel@reliant.home.pri> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 22 Feb 2003 09:14:43 -0600 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/96 X-Sequence-Number: 3717 --=-VjSqap5BxGVJPoJUgvlJ Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Fri, 2003-02-21 at 02:37, Demetres Pantermalis wrote: > Thanks for your reply. >=20 > 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. >=20 > 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 ; >=20 > #line 21 "test2.pgc" > birthinfo birth ; > } personal , * p ; >=20 > 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), > ECPGt_int,&(i->ind_name),1L,1L,sizeof(int), > ECPGt_long,&(p->birth.born),1L,1L,sizeof(long), > ECPGt_long,&(i->ind_birth.born),1L,1L,sizeof(long), > ECPGt_short,&(p->birth.age),1L,1L,sizeof(short), > ECPGt_short,&(i->ind_birth.age),1L,1L,sizeof(short), > ECPGt_char,&(married),0L,1L,1*sizeof(char), > ECPGt_long,&(ind_married),1L,1L,sizeof(long), > ECPGt_int,&(children.integer),1L,1L,sizeof(int), > ECPGt_short,&(ind_children.smallint),1L,1L,sizeof(short), > ECPGt_EORT); >=20 > Everything is OK for C, but for C++ the struct 'varchar_name' is consider= ed > 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) =3D12) then the compilation with the C++ compiler is > successful... > 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 ...). >=20 > Another solution is to 'typedef' the varchar_name structure, before the > definition of the personal_struct (ie typedef struct varchar_name { int l= en; > 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!!! ). >=20 I don't think that will work. I can never get ecpg to recognize typedefed structs, even when declaring the typedefed struct within a DECLARE SECTION. Probably doing the sizeof calculation within ecpg would be the proper way to go, and using that value in the ECPGdo call instead of sizeof(whatever). With respect to C++, anyhow. I'm sure the developers would accept a patch, but realize that ecpg generates native C code, and follows C conventions. C++ may parse the code differently in some cases. Your best bet is going to be using the C compiler on these files to generate you object code, and your C++ compiler on your native C++ code, as Peter suggested. >=20 > -----Original Message----- > From: Peter Eisentraut [mailto:peter_e@gmx.net] > Sent: Thursday, February 20, 2003 7:16 PM > To: Demetres Pantermalis > Cc: pgsql-interfaces@postgresql.org > Subject: Re: [INTERFACES] ECPG and C++ compilation >=20 >=20 > Demetres Pantermalis writes: >=20 > > 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? >=20 > 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. >=20 --=20 Matthew Vanecek perl -e 'print $i=3Dpack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);' ***************************************************************************= ***** For 93 million miles, there is nothing between the sun and my shadow except= me. I'm always getting in the way of something... --=-VjSqap5BxGVJPoJUgvlJ Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQA+V5Pji/CNzDSN0RIRAjwuAKCZQoLff80rYvbGCDy88VjjVfkcjgCgoxCi rA9MnDYn6PA4tKvsz13vznI= =Q5gt -----END PGP SIGNATURE----- --=-VjSqap5BxGVJPoJUgvlJ--