mutual reference in structures

Mark A Terribile mat at mole-end.UUCP
Sat May 13 16:46:01 AEST 1989


In article <2346 at wheat-chex.ai.mit.edu>, jym at wheaties.ai.mit.edu (Jym Dyer) writes:

> VAX C accepts this (which seems wrong to me):
 
> 	typedef struct
> 	{
> 	  struct NODE_T *  flink_p;
> 	  struct NODE_T *  blink_p;
> 	  char  data[512];
> 	}  NODE_T;


Why does it seem wrong?  Yes, C accepts a structure tag before the structure's
form is available.  Without this leniency, you need either to allow forward
declarations (a pain and easy to get wrong) or to forgo any use of linked
lists.

 
> It would be nice if C typedefs knew about themselves.  That is, if this
>     worked:


Now you are getting into there area where forward declarations would be
needed.

 
> 	typedef
> 	{
> 	  NODE_T *  flink_p;
> 	  NODE_T *  blink_p;
> 	  char  data[512];
> 	}  NODE_T;


The parser has to know that NODE_T is a type.  (This isn't absolutely true,
but if the grammar doesn't assume that lexical analysis can tell a type from
an ordinary identifier, you have push a much worse problem into semantic
analysis.)  It doesn't know that NODE_T is a type until the declaration has
been processed.

This is where you start talking about forward declarations.
-- 

 (This man's opinions are his own.)
 From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list