Re: ECPG and C++ compilation

From: Matthew Vanecek <mevanecek(at)yahoo(dot)com>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: Postgresql Interfaces List <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: ECPG and C++ compilation
Date: 2003-02-25 20:44:45
Message-ID: 1046205884.12260.77.camel@reliant.home.pri
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Mon, 2003-02-24 at 09:24, Michael Meskes wrote:
> On Sat, Feb 22, 2003 at 09:14:43AM -0600, Matthew Vanecek wrote:
> > 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.
>
> Now that I do not understand. What exactly doesn't work? do you have a
> small example?
>

#include <stdio.h>

EXEC SQL BEGIN DECLARE SECTION;
struct s_somestruct {
int id;
char *field;
};

typedef struct s_somestruct SomeStruct;
EXEC SQL END DECLARE SECTION;

int main(int argc, char **argv)
{
printf("this is just to show parse errors from ecpg\n");
return 0;
}

yields:

me2v(at)reliant conn $ ecpg example.pgc
example.pgc:7: ERROR: parse error at or near ";"

If instead I use:

#include <stdio.h>

struct s_somestruct {
int id;
char *field;
};

EXEC SQL BEGIN DECLARE SECTION;
typedef struct s_somestruct SomeStruct;
EXEC SQL END DECLARE SECTION;

int main(int argc, char **argv)
{
printf("this is just to show parse errors from ecpg\n");
return 0;
}

I get:
me2v(at)reliant conn $ ecpg example.pgc
example.pgc:9: ERROR: parse error at or near "SomeStruct"

I get this error also if I use:

EXEC SQL BEGIN DECLARE SECTION;
struct s_somestruct {
int id;
char *field;
} a_struct;

typedef struct s_somestruct SomeStruct;
EXEC SQL END DECLARE SECTION;

Doing "typedef struct { /* stuff */ } AStruct;" appears to work with
ecpg from 7.3.2, but IIRC, it would not work in 7.2.3.

> > 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
>
> But that would mean you cannot precompile on one machine for usage on
> another. Right?
>

Is sizeof() a compile-time execution/calculation? If so, then it would
definitely not be portable, unless you implemented/used a generic types
library (such as glib, for example). Since it works in C, though, and
ECPG generates C, I'm by no means making a suggestion to follow this
path. ;)

--
Matthew Vanecek
perl -e 'print $i=pack(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...

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Wei Weng 2003-02-25 20:58:20 Re: debug a mess
Previous Message Matthew Vanecek 2003-02-25 20:29:56 Re: debug a mess