Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!rutgers!mcnc!rti!xyzzy!nextuid From: nextuid@xyzzy.UUCP (Next User-id to allocate) Newsgroups: comp.lang.c Subject: Re: initialization of unions Message-ID: <356@xyzzy.UUCP> Date: Fri, 30-Oct-87 10:32:04 EST Article-I.D.: xyzzy.356 Posted: Fri Oct 30 10:32:04 1987 Date-Received: Wed, 4-Nov-87 22:49:31 EST References: <165600017@uiucdcsb> Reply-To: meissner@xyzzy.UUCP (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 19 In article <165600017@uiucdcsb> wsmith@uiucdcsb.cs.uiuc.edu writes: | | K&R say that if an initialization list is incomplete, the remaining fields | are initialized to zero, which works on all 4 compilers, if for example the | union is the last element of a structure and I do not leave a value for | that place. The difference occurs when I try to place a value into the | union field. 2 consider this to be an error, one bluntly saying: "unions | can not be initialized". The other two allow the initialization to take | place if the first option of the union matches the value being placed in. ANSI says that it legal to initialize a union, and by doing so, you use the first element of the union as the type to use when filling in the bits. Note, there have been some people who wrote in and said they thought the first member business was for the birds, and proposed various means to specify which member gets initialized. My personal feeling is the first member is more in the spirit of K&R C, and that a much better scheme would be to allow you to specify the name of the field being initialized ala ADA. I don't know how many times I have changed the order of fields in a structure and then had to go find all cases of initialization and fix them as well.