Must a NULL pointer be a 0 bit pattern?
Hokey
hokey at plus5.UUCP
Fri Oct 19 16:29:55 AEST 1984
> ANSI C deals with this by giving a rule for explicit initialization
> of unions: the first member is the one that is initialized. Implicit
> initialization can use the same rule, meaning that in the above example,
> only p_member would be guaranteed to start out as a zero (null) value.
I'm not up on the reasons for using the first member of the union being
the one which is initialized.
I can see how initialization of unions can be very useful (I need it
in several places), but why the constraint on the type? If I have an
external structure in which a member is a union which I want to initialize,
I gather I am out of luck unless the elements of the union which I am
initializing are of the same type.
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;...".
Can somebody tell me either why the ANSI C restriction is there, or
where I am missing the point?
--
Hokey ..ihnp4!plus5!hokey
314-725-9492
More information about the Comp.lang.c
mailing list