if (p), where p is a pointer

Ephraim Vishniac vishniac at wanginst.UUCP
Fri Sep 13 22:06:20 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?
> 
> No, you don't need to say NULL explicitly.  The relevant rules are:

	1. You should only make explicit comparisons in your code *only* where
	   absolutely necessary.  Not only does this save at least 1% in
	   editing keystrokes, but it deters nosy people from reading (or,
	   at least, from understanding) your code.

The way I see it, portability is not the essential issue here: *clarity* is.
-- 
Ephraim Vishniac
  [apollo, bbncca, cadmus, decvax, harvard, linus, masscomp]!wanginst!vishniac
  vishniac%Wang-Inst at Csnet-Relay



More information about the Comp.lang.c mailing list