[net.lang.c] NULL pointers vs. integers

henry@utzoo.UUCP (Henry Spencer) (09/13/85)

> External variables are to be initialized to 0, according to the C Reference
> Manual...
> ...Since this
> includes all variables not explicitly initialized, it includes unions.
> It is hard to imagine an implementation of this that allows a block of
> memory representing simultaneously one or more pointers and one or more
> integers to be initialized correctly unless the bit pattern for a null
> pointer is identical to the bit pattern for a 0 integer of the same size
> ...
> Therefore, unless you accept a brain-damaged compiler that treats 'union'
> as equivalent to 'struct,' it seems hard to avoid the conclusion that
> C requires that the bit-pattern for a "null" pointer be identical to the
> bit pattern of "(int) 0" (except possibly in length).

Beware of reading more into K&R than is really there!  Given that at most
one member of a union can be stored in the union at any one time (K&R p197),
what does it *mean* for a union to be initialized to zero?  The best answer
to the question is not "K&R implies that pointer and integer 0 must be the
same" but "K&R does not specify the initial value of external unions".

This is not net.religion.dogmatic, where the holy scriptures are assumed
to automatically have the answers to all questions, and any random choice
of phrasing is inherently full of deep meaning if you read it correctly.
Nor is it net.education.exams, where "I don't know" gets you a mark of 0.
Remember that K&R is old, was written before a lot of these issues came
up in a serious way, and was never intended to be a rigorous formal
definition implicitly containing the answer to every possible question.

The ANSI C-standard draft resolves the issue by saying that unions are
initialized by initializing their first member.  This may not suffice
for all the uses one would want (let's not start *that* debate again!),
but it does suffice to make the default initialization unambiguous.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry