Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site chalmers.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!mcvax!enea!chalmers!augustss From: augustss@chalmers.UUCP (Lennart Augustsson) Newsgroups: net.lang.c Subject: Re: Standard for union initializatio Message-ID: <225@chalmers.UUCP> Date: Fri, 1-Feb-85 03:43:47 EST Article-I.D.: chalmers.225 Posted: Fri Feb 1 03:43:47 1985 Date-Received: Mon, 4-Feb-85 03:37:21 EST References: <137@ISM780B.UUCP> <11143@watmath.UUCP> Reply-To: augustss@chalmers.UUCP (Lennart augustsson) Distribution: net.lang.c Organization: Dept. of CS, Chalmers, Sweden Lines: 35 In article <11143@watmath.UUCP> kpmartin@watmath.UUCP (Kevin Martin) writes: >... >>> >>> 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. >... >"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. Doesn't the same argument hold for structures too? Do you want to change the initialization of them? I think the original suggestion is quite reasonable. -- Any resemblance of the opinions above to real opinions, living or dead, is purely coincidential. Lennart Augustsson {seismo,philabs,decvax}!mcvax!enea!chalmers!augustss