Must a NULL pointer be a 0 bit patte

jim at ISM780B.UUCP jim at ISM780B.UUCP
Sun Nov 4 03:30:55 AEST 1984


>Three comments about non-zero NULL:
>
>1. Because of implicit comparison with zero, as in "while(p)s;", this idea
>is cannot be implemented simply by changing stdio.h to read
>#define NULL ((char*)0x87654321)

I think you have misunderstood.  There is no intention to change the
definition of NULL.  The changes are in the compiler, to interpret the
constant "0" as different from all zero bits.  Thus,

	register char *p = 0;

would compile into

	l   regp,=x'87654321'

Under no circumstances does "while(p)" have semantics different from
"while(p != 0)" in C.


>2. In making changes to the compiler, this must remain zero:
>        (p = NULL , (int)p)

The language spec does not guarantee it.  In fact, it explicitly considers
the result of this expression to be implementation-dependent.

>Also, for every declared "var", this must remain one:
>        (p = &var , (int)p != 0)

Ditto.  In fact, regardless of the handling of NULL pointers, this expression
may yield zero on machines with ints smaller than pointers, if the low-order
bits of &var are zero.  All of this has been discussed here before.

>3. The issue of how a union can be set to zero was handled properly by the
>correspondent who said the first member is initialized to zero.

Statements like "so and so is right" or "I am for X" without analysis and
argument are rather arrogant.  If you think it is right say why, and
refute other positions (such as that it may be desirable to initialize
different members of different instances of the same union).
I have yet to see an argument *for* always initializing the first member,
other than "all the other methods have problems".  Enumerate the other
methods; state their problems.

I suggest that if an initializer of a union has no explicit cast, it be
converted to the type of the first member, otherwise it has an explicit
content which should become the content of the union, provided it is
type-compatible with at least one member of the union.  The default case
guarantees that this is at least as powerful as "initialize first member".
It is unambiguous, it is complete if it is recognized that (char *)"abc" and
(char [])"abc" produce different "values", and it is compatible in form with
the existing language.

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



More information about the Comp.lang.c mailing list