Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!ginosko!usc!merlin.usc.edu!nunki.usc.edu!jeenglis From: jeenglis@nunki.usc.edu (Joe English) Newsgroups: comp.lang.c Subject: Re: on the fringe of C syntax/semantics Message-ID: <5560@merlin.usc.edu> Date: 6 Oct 89 19:52:57 GMT References: <80100001@bonzo> <453@usage.csd.unsw.oz> Sender: news@merlin.usc.edu Reply-To: jeenglis@nunki.usc.edu (Joe English) Distribution: na Organization: University of Southern California, Los Angeles, CA Lines: 46 troy@mr_plod.cbme.unsw.oz writes: >This isn't really on the edge of the language specs.... although I ran into >a question last night which was... somebody wanted to define a pair of >structures which were initialised with pointers to eachother. [...] >struct a_struct { > void *next; > int value; >}; > >struct b_struct { > struct a_struct *next; > int value; >}; Except you probably shouldn't use void *. I just tried this, and both gcc and cc (SunOS) accepted it: struct foo; /* forward declaration -- unnecessary, though */ struct bar { struct foo *foop; /* this is OK. */ }; struct foo { struct bar *barp; /* OK, struct bar seen alrerady */ struct diddle *diddlep; /* OK, struct diddle defined later */ struct qwerty *qwertyp; /* OK, struct qwerty *never* defined */ }; struct diddle { int asdf; }; Presumably the compiler would complain if I tried to use a foo::qwertyp before it had seen the definition of struct qwerty, but the rest worked just fine. (BTW, is this behaviour specified in the standard?) --Joe English jeenglis@nunki.usc.edu