Re: HELP: typedef link list node in ESQL/C
Posted in 1997
Dennis, I'm sending this to c.d.i too as it may be useful to other people.
>Date: Tue, 03 Jun 1997 16:01:44 -0500
>From: Dennis Bowen <dbowen@pamd.cig.mot.com>
>
>Thank you for your quick response. Unfortunately, I'm still having
>problems. I cut and pasted your suggestion:
>
>EXEC SQL BEGIN DECLARE SECTION;
>typedef struct Node *pNODE;
>typedef struct Node
>{
> int var1;
> pNODE prev;
> pNODE next;
>} NODE;
>EXEC SQL END DECLARE SECTION;
>
>This gives me the following error message:
>
>$ esql -e -Aa dcb.ec>esqlc: "node.ec", line 2: Error -33200: Invalid statement on symbol
>'Node'.
>
>$ esql -V
>INFORMIX-ESQL Version 5.01.UD1>Software Serial Number AAA#B607931
>
>I am running on HP-UX 9.05
Well, I get the same problem on SunOS 4.1.x with 5.01.UC2 ESQL/C, so things
improved over time during the 5.0x releases. You'll have to revert to the
mechanism that'll work with 4.1x too:
EXEC SQL BEGIN DECLARE SECTION;
typedef struct Node
{
int var1;
struct Node *prev;
struct Node *next;
} NODE;
typedef struct Node *pNODE;
EXEC SQL END DECLARE SECTION;
I tested this explicitly with 4.10.UC1 and 5.01.UC2 on SunOS.
Speaking for myself, I dislike typedefs for structures
which conceal
pointers. The worst code for this which I know of has a whole pile of
'class abcDef' types with (consistently) the typedefs 'typedef class abcDef
*AbcDef;'. Now go and read some new code and spot the problems in the
constructor:
class someClass
{
AbcDef a;
defGhi b;
...
};
I wouldn't use pNODE. On the other hand, for complex function pointers,
typedefs are sometimes necessary (or, at least, beneficial):
typedef void (*Handler)(int);
extern Handler signal(int, Handler);
versus:
extern void (*signal(int, void (*)(int)))(int);
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>