if (p), where p is a pointer (REAL portability)

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Fri Sep 13 23:04:23 AEST 1985


> I have to disagree with A. Koenig's reply.  The rules he cites are
> accurate, but the conclusions are unsafe.

Sorry, Stu, but Andy was completely correct and you are wrong.

> A constant zero IS safely converted into a "null" pointer of the
> appropriate type.  IT IS NOT THE CASE that a "null" pointer of an
> arbitrary type is converted to or represented by all zero bits.

No one said anything about representing a null pointer by "zero bits".
The integer constant 0, written in the source code, is guaranteed to
compare equal to a null pointer, and there are some other guarantees
(NOT including bit pattern for a null pointer).

>   char *p;
>   if (p)			/* NOT PORTABLE */

Rong.

> Moreover, saying that NULL must be defined as zero is putting the cart
> before the horse.  NULL must be defined as an invalid (char *) pointer
> and if your machine architecture wants that to be 0x555555, then that
> is what NULL should be defined as.  It is coincidental and NONPORTABLE
> that NULL is usually defined as 0.

Rong.  The only portable definition of NULL is as 0.

> NULL is NOT guaranteed to be canonical "null" pointer for any type
> other than (char *).

Where did you get this idea?

Please read the X3J11 information bulletin.



More information about the Comp.lang.c mailing list