[gnu.gcc.bug] bug in gcc-1.36 structure initialization .

TRANLE@INTELLICORP.COM (Minh Tran-Le) (01/17/90)

gcc 1.36 does not seems to be able to compile the following file:

/* -- start of file test.c -- */
typedef union _MyUnion {
	char * str;
	long   uval;
} MyUnion;

typedef struct _MyStruct {
	MyUnion name;
} MyStruct;

MyStruct abc = { 0 };
/* -- end of file test.c -- */


Here is what I got when trying to compile it:

1 paris:mtranle> gcc -c -v test.c
gcc version 1.36
 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dunix -Di386 -DAIX -D__unix__ -D__i386__ -D__AIX__ test.c /tmp/ccaaafOu.cpp
GNU CPP version 1.36
 /usr/local/lib/gcc-cc1 /tmp/ccaaafOu.cpp -quiet -dumpbase test.c -version -o /tmp/ccaaafOu.s
GNU C version 1.36 (80386, ATT syntax) compiled by GNU C version 1.36.
default target switches: -m80387
test.c:11: type mismatch in initialization
2 paris:mtranle> 

Does anybody knows about a fix or a work around for it ?

Thanks, Tran-Le.

Arpanet: tranle@intellicorp.com
uucp:    ..sun!icmv!mtranle
-------

alexande@unc.cs.unc.edu (Geoffrey D. Alexander) (01/18/90)

K&R, 2nd edition states the following in section A8.7 (bottom of page 219):

   The initializer for a union is either a single expression of the same
   type, or a brace-enclosed initializer for the first member of the union.

Note that MyStruct has one member of type MyUnion.  Since type MyUnion is a
union, it must either be initialize by an expression of type MyUnion or an
brace_enclosed initializer for the first member of the union which has type
char*.  I assume you wish to initialize abc.name to 0.  To do this, you must
have two set of braces:

  MyStruct abc = { {0} }

This compiles without error under gcc 1.36 on a Sun-3M60 running SunOS 4.0.3.
I don't believe the problem you reported is a bug.

Geoff Alexander

alexande@unc.cs.unc.edu (Geoffrey D. Alexander) (01/21/90)

In article <11506@thorin.cs.unc.edu> I write:
 >K&R, 2nd edition states the following in section A8.7 (bottom of page 219):
 >
 >   The initializer for a union is either a single expression of the same
 >   type, or a brace-enclosed initializer for the first member of the union.
 >
 >Note that MyStruct has one member of type MyUnion.  Since type MyUnion is a
 >union, it must either be initialize by an expression of type MyUnion or an
 >brace_enclosed initializer for the first member of the union which has type
 >char*.  I assume you wish to initialize abc.name to 0.  To do this, you must
 >have two set of braces:
 >
 >  MyStruct abc = { {0} }
 >
 >This compiles without error under gcc 1.36 on a Sun-3M60 running SunOS 4.0.3.
 >I don't believe the problem you reported is a bug.
 >
 >Geoff Alexander

If have been informed, although K&R 2ed doesn't mention it, that the ANSI
standard allows the inner set of braces to be dropped in this case.  The
problem reported is actually a bug.  However, the work-around is to use
two sets of braces until there is a fix.

Geoff Alexander