use of if (!cptr) and if (cptr), where cptr is a *

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Jul 20 02:21:55 AEST 1989


In article <10100 at mpx2.mpx.com> erik at mpx2.mpx.com (Erik Murrey) writes:
>Now, what happens with:
>if (cptr == 0) ?  Does the compiler cast the cptr to an int, and loose
>the descriptor?  (And tell is that it is null?)

We've already explained this, but here it is again:  Just because you
see "0" in the source code does not mean that it acts an integer constant.
In this context it is taken as (technically, is converted to) a null
pointer of the appropriate type.  A null pointer need not have an all-0 bit
representation, but "0" is still the way you write it in C source code.

In effect, the apparent integer constant "0" is converted to a pointer in
this context; the pointer is not converted to int.

>How about:
>if (!cptr) ?

Completely equivalent to "if(cptr==0)".



More information about the Comp.lang.c mailing list