use of if (!cptr) and if (cptr), where cptr is a *
Eric Giguere
jyegiguere at lion.waterloo.edu
Thu Jul 20 11:37:26 AEST 1989
The following quote from the draft ANSI Standard should be of interest:
"An integral constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant." (3.2.2.3)
and then later
"NULL ... expands to an implementation-defined null pointer constant"
(4.1.5)
So even if your compiler uses its own non-zero internal representation
for the null pointer, it must be able to catch expressions of the form
if( ptr != 0 )
if( ptr != ( 10 * 10 - 101 + 1 ) )
if( ptr != (void *) (5-5) )
and your macro for NULL better expand to a zero-valued integer expression.
Eric Giguere 268 Phillip St #CL-46
For the curious: it's French ("jee-gair") Waterloo, Ontario N2L 6G9
Bitnet : GIGUERE at WATCSG (519) 746-6565
Internet: giguere at aries5.UWaterloo.ca "Nothing but urges from HELL!!"
More information about the Comp.lang.c
mailing list