Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!munnari.oz.au!csc.anu.oz.au!csc3.anu.oz.au!anucsd!csc.canberra.edu.au!news From: eyal@echo.canberra.edu.au (Eyal Lebedinsky) Newsgroups: comp.lang.c Subject: Re: initializing static mutually referencing structures Message-ID: <1990Sep21.230632.19238@csc.canberra.edu.au> Date: 21 Sep 90 23:06:32 GMT References: <1287@granjon.UUCP> Sender: news@csc.canberra.edu.au Distribution: usa Organization: none Lines: 32 In article <1287@granjon.UUCP> jhpb@granjon.att.com (01000-JH Buehler(BLU123)) writes: >I have some structures that refer to each other, that I want to be >static. The compiler doesn't like the following because it doesn't know >what y is when it's initializing x: > > static struct xtag x = { > &y; > }; > > static struct ytag y = { > &x; > }; > >Does ANSI C have any way to do this? For now, I had to drop the static ANSI asks you to add a line: extern struct ytag y; before the first definition. Note that 'extern' does not mean that y is 'external to this file' but that 'it is defined elsewhere'. The 'static' definition later will complete the meaning. Some one-pass compilers will have lots of trouble with this. ANSI 3.7.2 explaines this 'tentative definition' stuff. It says that saying 'static struct ytag y;' should work because this is tentative and the later initialized definition is real. I know that some compilers don't like this either. This is generaly a sticky area. NOTE that I said to leave the rest of your example as is, with the 'static's. >-- >Joe Buehler -- Regards Eyal