if (p), where p is a pointer

Ron Newman newman at mit-hector.UUCP
Wed Sep 11 13:31:46 AEST 1985


With all this talk about NULL pointers not necessarily being equal to 0,
I'm no longer sure what is and isn't portable code.  An C idiom I see 
(and write) frequently is

	<some type> *ptr;
	...
	if (ptr)
	   <statement>

Will this work correctly on a machine where NULL is not 0?  Does it really
need to say

	if (ptr != NULL)

??

(Disclaimer:  I've only known C and Unix for nine months, and have used only
Berkeley 4.2 and only on a VAX.   Thus the discussion about NULL and 0
being non-equivalent came as a great shock.)

/Ron Newman, MIT Project Athena



More information about the Comp.lang.c mailing list