Standard for union initializatio

Lennart Augustsson augustss at chalmers.UUCP
Fri Feb 1 18:43:47 AEST 1985


In article <11143 at watmath.UUCP> kpmartin at 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



More information about the Comp.lang.c mailing list