structure initialization

Richard Bumby bumby at math.rutgers.edu
Fri Feb 2 01:43:54 AEST 1990


In <1515 at pttesac>, jeapedai at 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 at math.rutgers.edu
  voice communication unreliable -- telephone ignored -- please use Email



More information about the Comp.lang.c mailing list