Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: initializing static mutually referencing structures Message-ID: <18201:Sep2203:25:3190@kramden.acf.nyu.edu> Date: 22 Sep 90 03:25:31 GMT References: <1287@granjon.UUCP> <186@thor.UUCP> Distribution: usa Organization: IR Lines: 20 In article <186@thor.UUCP> scjones@thor.UUCP (Larry Jones) writes: > In article <1287@granjon.UUCP>, jhpb@granjon.UUCP (Joseph H. Buehler) 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}; A different approach should work under any C compiler, though it may not be implemented efficiently. It also has the usual syntactic problems of macros. static struct { struct xtag x; struct ytag y; } shmoe = { &(shmoe.y), &(shmoe.x) } ; #define x (shmoe.x) #define y (shmoe.y) Caveat: This is untested. But the idea is useful to remember. ---Dan