Mail Archives: djgpp/1998/11/14/17:00:28
Wouter Bijlsma wrote:
> How can I define a recursive structure without getting parse errors or
> 'incomplete data type' errors?
>
> typedef struct {
> unsigned Tag;
> Plane *RootPlane;
> BSPNode *FrontNode,BackNode;
> Polygon *Polygons;
> } BSPNode;
>
> This does *not* work....
You are defining an anonymous struct, and then typedef'ing it tp
BSPNode. The problem is, by the time the BSPNode * members are
encountered by the compiler, BSPNode is an incomplete type, because it
has not yet been defined (it is defined after the struct is defined).
There are two solutions:
Create the typedef first, then the struct:
typedef struct S S;
struct S {
...
S *s;
};
or you can refer to the structure itself with a tag, rather than with
the typedef:
typedef struct S {
...
struct S *s;
};
Note that in either case you must give the struct a tag (which you are
not doing above).
In C++ these kinds of things do not cause a problem since reference to
structs by tag is no longer necessary.
--
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900
Alcyone Systems / irc maxxon (efnet) / finger max AT sade DOT alcyone DOT com
San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
\
/ The pure and simple truth is rarely pure and never simple.
/ Oscar Wilde
- Raw text -