struct a <---> struct b

Lawrence V. Cipriani lvc at tut.cis.ohio-state.edu
Mon Feb 15 04:52:55 AEST 1988


In article <11774 at brl-adm.ARPA> Alan_T._Cote.OsbuSouth at Xerox.COM writes:
>Finally -- one I can answer!!
>
>>What is the best way to declare three different structures, each containing a pointer
>>to the other two? I keep running into a forward referencing error.
>
>Try declaring all three as externals ahead of time.  Try the following:

The way I took this question was that the different structures are also of
different type.  If this is the case the answer is different.  Do the
following:

	struct a;	/* Hey compiler! a b and c are structures */
	struct b;	/* that I will define later */
	struct c;

	struct a
	{
		struct b *pb;
		struct c *pc;
		...	/* other stuff */
	};

	struct b
	{
		struct a *pa;
		struct c *pc;
		...	/* other stuff */
	};

	struct c
	{
		struct b *pb;
		struct c *pc;
		...	/* other stuff */
	};

The initialization of the pointers is left as an exercise for the
interested reader.

-- 
oo
Larry Cipriani, AT&T Networks Systems (by day) Ohio State University (by night)
Domain: lvc at tut.cis.ohio-state.edu
Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (yes its right)



More information about the Comp.lang.c mailing list