Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!batcomputer!gould!steinmetz!uunet!modcomp!joe From: joe@modcomp.UUCP Newsgroups: comp.lang.c Subject: Re: static list initialization Message-ID: <8000008@modcomp> Date: 16 Oct 88 15:13:00 GMT References: <196@donk.UUCP> Lines: 26 Nf-ID: #R:donk.UUCP:196:modcomp:8000008:000:1204 Nf-From: modcomp.UUCP!joe Oct 16 11:13:00 1988 > Here's a fragment of code I find myself staring at glumly from time to time. > It sets up the nucleus of a 2-way list, into which extra malloc'd nodes will > be inserted. > > struct whatever { > struct whatever *next; /* next node */ > struct whatever *prev; /* previous node */ > int eresting_stuff; /* blah, blah, ... */ > }; > extern struct whatever tail; > static struct whatever head = { &tail, (struct whatever *)0 }; > static struct whatever tail = { (struct whatever *)0, &head }; > > Without the 'extern', the compiler can't initialize 'head'. But with it, I > get a 'non-standard extension' warning, although everything works just fine. This kind of initialization can only be safely done at run time. Even if you found a compiler that would accept such an unethical sequence of code, (two variables named "tail" -- wow!), you should not use it -- it would be unportable, even to a different C compiler on the same machine/OS. However, I see how being able to forward reference structures, just as easily as we can forward reference structure pointers today, could be appealing. Joe Korty uunet!modcomp!joe