What C compilers have non-zero null pointers?

Stephen Clamage steve at taumet.com
Thu Jul 19 01:52:27 AEST 1990


ergo at netcom.UUCP (Isaac Rabinovitch) writes:

>But what the "NULL should always be 0" diehards want is not to
>write (for example)
>	for (ptr = fist; ptr != 0; ptr = ptr->next)
>in which 0 should probably be #DEFINED anyway, but rather
>	for (ptr = first; ptr ; ptr = ptr->next)
>which produces tighter code ...

If in this context the expression
	ptr
produces code which is better than
	ptr != 0
then you are the victim of a lazy compiler writer.  There should be
no difference, since 'ptr' is shorthand for 'ptr != 0'.  I would
complain to the vendor, or buy a better compiler.

This is the sort of micro-optimization that programmers in a higher
level language should NOT have to worry about.  On compiler A, one
code version may produce a more efficient program; on compiler B, the
reverse may be true.  Compiler B might even be the next release of
compiler A.  Thus, the effort spent in this micro-optimization is
not only wastful, but may be counter-productive over time.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list