Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!accuvax.nwu.edu!tank!ncar!unmvax!deimos.cis.ksu.edu!rutgers!att!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c Subject: Re: mutual reference in structures Summary: Nothing wrong here ... Message-ID: <188@mole-end.UUCP> Date: 13 May 89 06:46:01 GMT References: <6712@medusa.cs.purdue.edu> <1822@ubu.warwick.UUCP> <2346@wheat-chex.ai.mit.edu> Organization: mole-end--private system. admin: mole-end!newtnews Lines: 46 In article <2346@wheat-chex.ai.mit.edu>, jym@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