From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aurel Balmosan To: Alexandre Oliva , egcs-bugs Subject: Re: Initialising an union Date: Wed, 19 Aug 1998 02:44:00 -0000 Message-id: <35DA8595.B69BDFC4@orga.com> References: <35D92F35.280D31A1@orga.com> X-SW-Source: 1998-08/msg00378.html List-Id: Alexandre Oliva wrote: > Aurel Balmosan writes: > > > You will notice that the union X is not fully initialised. > > What do you mean by fully initializing a union? You have initialized > it with only an integer, so only the first integer field will be > initialized; the remaining fields need not be, because you have not > initialized them. As it is defined in ANSI-C a struct where only the first part is initialised is filled with zero's. As for gcc-2.7.2.3 and older versions the union was fully initialised. This is not any more with egcs-1.0.3a which we now use. Either the gcc-2.7.2.3 and older used a not ANSI-C comform initialising for unions or the egcs-1.0.3a does not follow ANSI-C in this part. structs are fully initialised to zero when one say ie: struct c { int a; double b; char c[123]; }; struct d { char c[234]; char d[231]; int e; }; struct c Y = { 0 }; struct d Z = { 0 }; This is with gcc-2.7.2.3 and older as well as egcs-1.0.3a. Only the union is not! And thats my problem and a bug in egcs-1.0.3a This is defined in the ANSI-C Language Reference A.8.7: Initialisation I have currently only the german version but here the sentence which describes that behaviour and applies for struct's as well as for union's: initializer: assignment-expression { initializer-list } { initializer-list, } initializer-list: initializer, initializer-list, initializer Contains the initializer-list less initializer then the structure component has the rest values will be set to zero. There must not be more initializer than values in a structure component. I think that makes it clear. Bye, Aurel. -- Aurel Balmosan | Department SE-SW ORGA Kartensysteme GmbH | phone: +49 5254 991 824 An der Kapelle 2 | fax : +49 5254 991 749 33104 Paderborn, Germany | mailto:ab@orga.com