Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: structure initialization Keywords: braces Message-ID: <22237@mimsy.umd.edu> Date: 2 Feb 90 00:58:44 GMT References: Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 50 In article bumby@math.rutgers.edu (Richard Bumby) writes: >Is it possible that the typedef introduces the need for an extra level >of bracketing on some compilers? No. Aggregate initialisers always take one level of braces for each aggregate. In this case---where we had struct exp1 { int length; long grp1; long grp2; }; typedef struct { struct exp1 blk[5]; } RANGE; an object of type `RANGE' needed a brace because it was a struct, plus a brace because the (single) element of that struct was an array; then, each element of the array needed a brace because it was a struct. Had the type definition been typedef struct { int somevalue; struct exp1 b1; struct exp1 b2[2]; int othervalue; } RANGE; this might have been more obvious: RANGE x = { /* somevalue */ 1, /* b1 */ { 1, 2, 3 }, /* b2 */ { /* b2[0] */ { 4, 5, 6 }, /* b2[1] */ { 7, 8, 9 }, /* b2 */ } /* othervalue */ 0 }; If you drop all but the b2/b2[0]/b2[1]/b2 lines, you get RANGE x = { { { 4, 5, 6 }, { 7, 8, 9 } } }; -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris