Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!think.com!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: Forward referrence of static variables. Message-ID: <21059:Jan221:03:4191@kramden.acf.nyu.edu> Date: 2 Jan 91 21:03:41 GMT References: <1991Jan2.084213.19442@cai.uucp> <24413@grebyn.com> Distribution: usa Organization: IR Lines: 31 In article <24413@grebyn.com> ckp@grebyn.UUCP (Checkpoint Technologies) writes: > In article <1991Jan2.084213.19442@cai.uucp> davel@cai.UUCP (David W. Lauderback) writes: > >I think there is no "clean" solution to the problem > In fact, I may have an appropriate solution. Here is a clean solution. A few compilers may not implement it with full efficiency, and it has the usual syntactic problems of macros, but it does the trick. If you want to do something like this: static struct ll first = { 0, &last /* , more data */ }; static struct mm last = { &first, 0 /* , more data */ }; then do this: static struct { struct ll first; struct mm last; } shmoe = { { 0, &(shmoe.last) /*, more data */ } , { &(shmoe.first), 0 /*, more data */ } } ; #define first (shmoe.first) #define last (shmoe.last) Third time I've posted this since late September. I'd say it's FAQ time. > This won't work if you have different > structure types to resolve this way; This one will. ---Dan