union initialization

utzoo!decvax!genradbo!mitccc!zrm utzoo!decvax!genradbo!mitccc!zrm
Mon Dec 20 23:26:18 AEST 1982


Yes! Legalize union initialization! But please lets have some reasonable
convesion for what gets what value. Whitesmith's C, as I remember
*requires* that structures be initialized and the rules are that the
value you initialize with must be of the type of the first object in the
union. The reason for such a rule becomes clear in an  example just like
the one submitted by the person sugesting this extension.

union foo
{
	char *bar;
	char baz[4];
}
mumble = "quux";

In the absence of hard fast rules, this could have several meanings. 1)
"The right thing" -- Initialize baz to contain "quux". 2) Or it could
mean initialize bar to *point* to the constant string "quux". Clearly
wrong, but since when do compilers know from wrong? 3) Or, perhaps even
more horribly, it could stuff q, u, u, and x in the location of the
symbol bar, but in the wrong byte order!

Yow! Are we suffering in a Safeway?

Cheers,
Zig



More information about the Comp.lang.c mailing list