Re: HELP: typedef link list node in ESQL/C
Posted in 1997
>From: Dennis Bowen <dbowen@pamd.cig.mot.com> >Date: Tue, 03 Jun 1997 10:31:37 -0500 >X-Informix-List-Id: <news.38677> > >I want to make the following typedef available as a host variable: > >typedef struct NODE *pNODE; >typedef struct { > int var1; > pNode prev; > pNode next; >} NODE; Well, taking the declarations you've written as C code and handing them to GCC 2.7.2.2, I get the error messages: node.c:4: parse error before `pNode' node.c:4: warning: no semicolon at end of struct or union node.c:5: warning: data definition has no type or storage class node.c:6: warning: data definition has no type or storage class Since what you've got isn't yet valid C, it isn't clear that the ESQL/C compiler has to handle it other than by producing an error either. Presumably, you intended to write: typedef struct NODE *pNODE; typedef struct { int var1; pNODE prev; pNODE next; } NODE; This now compiles, but probably doesn't do what you think it will do. Strictly, the prev and next pointers point to some incomplete type 'struct NODE', which is different from the complete (untagged) struct typedef'd to NODE. You'd discover this when you tried to dereference the next/prev pointers: void f(void) { NODE *this = (NODE *)malloc(sizeof(NODE)); this->prev = this->next = this; if (this->prev->next != this->next->prev) error("Oops!"); } GCC says: node.c: In function `f': node.c:12: warning: assignment from incompatible pointer type node.c:13: dereferencing pointer to incomplete type node.c:13: dereferencing pointer to incomplete type So, you probably wanted: typedef struct NODE *pNODE; typedef struct NODE { int var1; pNODE prev; pNODE next; } NODE; This now compiles OK. We just need to get it through the ESQL/C compiler. Using this almost works: EXEC SQL BEGIN DECLARE SECTION; typedef struct NODE *pNODE; typedef struct NODE { int var1; pNODE prev; pNODE next; } NODE; EXEC SQL END DECLARE SECTION; It gives error: esqlc: "node.ec", line 9: Error -33050: The type or subtype 'NODE' has already been used. So, changing the code to: 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 work with the 5.08.UD1 ESQL/C compiler on Solaris 2.5.1, and should work on all versions of ESQL/C 5.0x or later. It doesn't work with 4.12.UC1 ESQL/C compilers. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>