Standard for union initializatio

jim at ISM780B.UUCP jim at ISM780B.UUCP
Wed Jan 23 15:52:59 AEST 1985


>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.

Very very nice!  And if structure initialization is extended to allow
(internal, due to the trailing comma hack) empty initializers to yield the
default value (0), it is totally isomorphic.
I presume that `ixstr = {, 3.14}' is ok.
So the "first member rule" becomes the "<number of leading commas>+1'th
member rule".  Note that this is even compatible with the first member rule
that Whitesmith's already implements, so Plauger will have no reason to
quash it.  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.

-- Jim Balter, INTERACTIVE Systems (ima!jim)



More information about the Comp.lang.c mailing list