Let's define our own NULL

Doug Gwyn gwyn at brl-smoke.ARPA
Fri Jun 24 01:52:02 AEST 1988


In article <160 at navtech.uucp> mark at navtech.uucp (Mark Stevans) writes:
>		#ifndef NULL
>		#define NULL	0
>		#endif

In fact I do this in a header that I include after all system headers
needed for a source module have been included.  I use the symbol NULL
simply for readability; the macro is never necessary, since 0 is just
as good.  Of course you still need to cast the null pointer to the
appropriate type when using it as a function argument.

The only reason for the #ifndef NULL ... #endif is that the implementor
of <stdio.h> may have chosen ((void *)0) for the definition, which
would clash with my redefinition.  #undef NULL would serve just as well.

Lately I've been starting to think that plain 0 is just as readable..



More information about the Comp.lang.c mailing list