Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!gauss.rutgers.edu!math.rutgers.edu!bumby From: bumby@math.rutgers.edu (Richard Bumby) Newsgroups: comp.lang.c Subject: structure initialization Keywords: braces Message-ID: Date: 1 Feb 90 14:43:54 GMT Organization: Rutgers Univ., New Brunswick, N.J. Lines: 45 Cc: bumby In <1515@pttesac>, jeapedai@pttesac.UUCP (J. E. Apedaile) asked about the behavior of various compilers in initializing a structure. I apologize for bothering the net with my response, but I don't trust our mailer to get to him as none of the links on the printed path appear to be known. The code in question is: struct exp1 { int length; long grp1; long grp2; }; typedef struct { struct exp1 blk[5]; } RANGE; main() { static RANGE example = {{ /* brace added */ { 40, 0xcf000, 0xff000 }, { 50, 0x1cf000, 0x1ff000 }, { 60, 0x2cf000, 0x2ff000 }, { 70, 0x3cf000, 0x3ff000 }, { 80, 0x4cf000, 0x4ff000 }, }}; /* brace added */ ..... } The extra braces noted enable the compiler on my laptop to compile the program successfully and give the expected result when executed. Further insertion of braces gives errors again. I have yet to try this on other compilers. Is it possible that the typedef introduces the need for an extra level of bracketing on some compilers? -- --R. T. Bumby ** Math ** Rutgers ** New Brunswick ** NJ08903 ** USA -- above postal address abbreviated by internet to bumby@math.rutgers.edu voice communication unreliable -- telephone ignored -- please use Email