Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!sun-barr!rutgers!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.std.c Subject: Re: 3.7.2 External Object Definitions Message-ID: <14327:Feb622:47:1391@kramden.acf.nyu.edu> Date: 6 Feb 91 22:47:13 GMT References: Organization: IR Lines: 31 Say struct foo's first element points to struct bar, and vice versa. Here's how to initialize mutually referencing static structures: static struct { struct foo f; struct bar b; } x = { { &x.b }, { &x.f } }; Done. Most compilers will use fixed addresses for &x.b and &x.f, so this will be just as efficient as separate static structure declarations. In article eyal@echo.canberra.edu.au (Eyal Lebedinsky) writes: > It is obvious that the second object defined should first have a > forward declaration for the first object to be properly initialized. No need. > I know how shady this area is with traditional compilers and do not wish to > discuss it, so please limit replies to ANSI issues. No, the solution above works fine under any C compiler. This is the fourth time since September that the same question has come up in comp.lang.c (and now comp.std.c); my fingers are getting tired. Anyone else think this belongs in the comp.lang.c FAQ? Steve, are you listening? ---Dan