Must a NULL pointer be a 0 bit pattern?
Henry Spencer
henry at utzoo.UUCP
Tue Oct 23 03:59:26 AEST 1984
> It would be much more useful to be able to (explicitly) initialize a union
> to *any* legal value. I don't see why this is either bad or hard. K&R
> states in 6.8 (page 139) that "It is the responsibility of the programmer
> to keep track of what type is currently stored in a union;...".
The problem is, *which* member of the union are you initializing? If your
union has int and double members, and you initialize it to 0, which member
does this initialize? Remember that C converts int to double as necessary.
Suppressing the conversion for this case only is an awkward special case,
and creates other problems.
Nobody contends that the "first member" rule is a particularly useful way
of initializing unions. It is there because (a) "doing it right" isn't
easy and there is little experience with the problems created, but (b) it
really is necessary to make initialization of unions meaningful, if only
so you can answer questions like "what does initialization to 0 mean?".
The "first member" rule is solely a matter of needing to do something,
not having any clear indication that there is any "best" way, and wanting
to avoid dangerous complexity. The "first member" rule has the virtue
that there *is* implementation experience with it, so its effects are
understood to some extent. Not true of most alternatives.
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henry
More information about the Comp.lang.c
mailing list