Forward referrence of static variables.

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Thu Jan 3 08:03:41 AEST 1991


In article <24413 at grebyn.com> ckp at grebyn.UUCP (Checkpoint Technologies) writes:
> In article <1991Jan2.084213.19442 at cai.uucp> davel at 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



More information about the Comp.lang.c mailing list