Initialization of unions

Hokey hokey at plus5.UUCP
Thu Jun 6 13:48:04 AEST 1985


In article <477 at tjalk.UUCP> dick at tjalk.UUCP (Dick Grune) writes:
>I saw a suggestion for the initialization of unions 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.

I don't see this as sensible or readable (I'm not sure about hygienic, either).

For starters, if one has a union of many elements, the initialization string
is *huge*.  For another, if elements are added, deleted, or reordered, the
initialization string must be fixed.  Thirdly, one has to look at the
definition quite often when examining an array union initialization in order
to keep everything in perspective.

I still believe the best answer is to explicitly cast each initializer.

It sure would be nice if the net could get some additional feedback from
the Committee on this issue.
-- 
Hokey           ..ihnp4!plus5!hokey
		  314-725-9492



More information about the Comp.lang.c mailing list