initializing static mutually referencing structures

Eyal Lebedinsky eyal at echo.canberra.edu.au
Sat Sep 22 09:06:32 AEST 1990


In article <1287 at granjon.UUCP> jhpb at 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



More information about the Comp.lang.c mailing list