static list initialization

ajw ajw at donk.UUCP
Sat Oct 15 08:07:36 AEST 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.

Question is, is there a way to achieve this initialization within
the letter of the law, leaving 'head' and 'tail' both static?

If you want to e-mail, please use addresses below.  Ta muchly.

-- Alan Waldock                 ...{tektronix|sun}!ogcvax!omepd!ihf1!mdt!ajw
Intel Corp, HF2-37               OR            ...uunet!littlei!ihf1!mdt!ajw
5200 NE Elam Young Pkwy           OR EVEN               ajw at mdt.hf.intel.com
Hillsboro, OR. 97124-6497          OR IF ALL ELSE FAILS       (503) 696-2478
                                
Opinions individual author's. Read before breaking seal. No warranty implied.



More information about the Comp.lang.c mailing list