Abandon NULL for (0)

Karl Heuer karl at haddock.ima.isc.com
Sat Sep 23 01:42:26 AEST 1989


Some people have been raising the strawman that "(0)" is inferior to "NULL"
because of an implicit cast which they believe to be attached to the latter.

This is not true.  In C, *any* use of "NULL" in a portable context (namely,
anyplace where a null pointer constant of some type was intended, except for
an uncasted argument to a function not covered by a prototype%) may be safely
replaced with "(0)".  Hence, this is no reason to avoid using "(0)".

Despite which, there *are* good reasons for not doing it.  The word "NULL" has
been conventionally used for decades to represent a null pointer constant;
when I see it, I know that it's a pointer context.  The original poster seemed
to be recommending the use of redundant parens around the zero to convey this
same information, which would be okay except that it's not an established
convention already.  People will look at it and scratch their heads.

In particular, if I were maintaining that code, I'd change the "(0)"'s back to
"NULL"'s as fast as I found them.  And if NULL were misimplemented on that
implementation, I'd simply fix that problem, rather than pollute my own code
with a workaround.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
________
% In which case neither "NULL" nor "0" is portable; you need a cast.



More information about the Comp.lang.c mailing list