null pointers (was: negative addresses)

Mark Brader msb at sq.uucp
Thu May 26 10:17:23 AEST 1988


> An interesting point: ANSI does not define (at least not anywhere
> I can find it) the result of `x == y' when x and y are both null
> pointers.

No, this bug (which I, at least, pointed out in the first-round public
comments) has been fixed in the January 1988 draft.  I may as well quote the
paragraph preceding the new one, as well.  From section 3.2.2.3 (on page 38):

# An integral constant expression with the value 0, or such an expression
# converted to type void *, is called a "null pointer constant".  If a null
# pointer constant is assigned to or compared for equality to a pointer,
# the constant is converted to a pointer of that type.  Such a pointer,
# called a "null pointer", is guaranteed to compare unequal to a pointer
# to any object or function.
#
# Two null pointers, converted through possibly different sequences of
# casts to pointer types, shall compare equal.

By the way, section 4.1.5 guarantees on page 99 that the macro NULL,
defined in certain standard #include headers,

# expands to an implementation-defined null pointer constant

thus it could be #defined as 0, 0L, (void*)0, 1-1, etc., but not (char*)0,
which always was wrong.  This has stayed the same through several drafts
and I think it is most unlikely to change before the final Standard.

Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb at sq.com
#define	MSB(type)	(~(((unsigned type)-1)>>1))



More information about the Comp.lang.c mailing list