Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!twitch!anuck!jrl From: jrl@anuck.UUCP (j.r.lupien) Newsgroups: comp.lang.c Subject: Re: struct a <---> struct b Summary: nested struct defs Message-ID: <465@anuck.UUCP> Date: 9 Feb 88 20:36:41 GMT References: <173@heurikon.UUCP> Organization: AT&T Bell Labs, Andover Ma. Lines: 53 In article <173@heurikon.UUCP>, lampman@heurikon.UUCP (Ray Lampman) writes: > What is the best way to declare three different structures, each containing a po > inter to the other two? I keep running into a forward referencing error. I'm loo > king for a solution without typedef's, I'll add those later. aTdHvAaNnKcSe, Ray. > -- > - Ray Lampman (lampman@heurikon.UUCP) Hi, Ray, It'll be a miracle if you get this, with a path that long. So, I'm also posting it to the net, on the offchance that this will help other C programmers. Anyway, I've done this for two structs, as follows: struct _foo { struct _bar { struct _foo *fooptr; other_members_of_the_bar; } *barptr; other_foo_members; } the_foo; This works, I've used it with great success. Now, to expand the beast out to three levels, let's try: struct _foo { struct _bar { struct _zot { struct _foo *fooptr; struct _bar *barptr; other_zots; } *zotptr; struct _foo *fooptr; other_bars; } *barptr; struct _zot *zotptr; other_foos; } one_such_foo; Hang on a second, I'll try it: Indeed, this seems to win the chocolate covered milk biscuit. By all means, use this trick in good health. Credit to Pablo Halpern for the two-struct idea (good times at DCI). -John Lupien ihnp4!mvuxa!anuxh!jrl