negative addresses

Henry Spencer henry at utzoo.uucp
Fri May 20 03:27:57 AEST 1988


>		if (tp->t_tbuf.c_ptr) {
>The C standards I've seen so far are pretty clear in stating that the
>conditional is compared against zero.  There doesn't seem to be leeway
>to define pointer comparisons to be against some non-zero NULL value.

Sigh.  Not this again!  If you *read* the fine print in the standards,
you will find that this construct is 100.00000% equivalent to saying
"if (tp->t_tbuf.c_ptr != NULL) {".  In pointer contexts, which this
is, the integer constant 0 stands for "whatever bit pattern is used for
null pointers".  When p is a pointer, "if (p)", "if (p != 0)" and
"if (p != NULL)" are completely synonymous, by the definition of C.

The problem that does come up is that compilers in general cannot tell
whether a parameter in a function call is meant to be a pointer or not,
and hence cannot supply the automatic conversion.  There is also trouble
with programs that explicitly convert pointers to integers and back.
-- 
NASA is to spaceflight as            |  Henry Spencer @ U of Toronto Zoology
the Post Office is to mail.          | {ihnp4,decvax,uunet!mnetor}!utzoo!henry



More information about the Comp.lang.c mailing list