Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Re: Standard for union initializatio Message-ID: <11143@watmath.UUCP> Date: Sat, 26-Jan-85 18:52:04 EST Article-I.D.: watmath.11143 Posted: Sat Jan 26 18:52:04 1985 Date-Received: Sun, 27-Jan-85 07:40:52 EST References: <137@ISM780B.UUCP> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 30 Summary: >>I saw a suggestion in net.lang.c a few months ago that I found very sensible, >>readable and hygienic: >> >> union { >> int i; >> float x; >> char *str; >> } ixstr = { , 3.14, }; >> >>if you want it to start off as a float, etc. >> >>Note that: >>1. it is (almost) isomorphous to a struct initialization, >>2. it also works nicely for arrays of unions. > >Now if the committee continues to stick with the first member >rule despite intelligent ideas like this, we should petition ANSI >for a new committee. "Intelligent idea"??? This is just another accident waiting to happen! This looks ok for a nice short example like this, but frequently, the union's definition and initialization are far apart (and maybe in different source files). This makes it easy to add another union element, and inadvertantly screw up the initializers royally without as much as a peep from the compiler. The first-element rule is a reasonable default, and there have been far better suggestions than the above to select another element. Kevin Martin, UofW Software Development Group.