C++? when did that happen?

Tim Angus tim at ngus.net
Sat Oct 8 11:30:05 EDT 2005


On Sat, 8 Oct 2005 03:45:35 +0200 Ludwig wrote:
> Tim Angus wrote:
> > [...]
> > I'll say again, using 0 in place of NULL in C is perfectly valid and
> > correct. Yes, NULL is implementation defined, but that DOES NOT make
> > the use of 0 in place of NULL wrong, nor does it make it a "C++ism".
> 
> You cannot blindly replace NULL with 0. sizeof(0) != sizeof(NULL) on
> 64bit platforms. Variadic functions for example will break if you pass
> 0 where you wanted to pass NULL. So always use NULL if you refer to a
> pointer.

In the general case though, if you have a function:

void function( something *p );

...and you call it...

function( 0 );

...what the compiler actually emits is...

function( (something *)0 ); // where sizeof( 0 ) is the appropriate word
size

The sizeof 0 doesn't matter since 0 is really being used as a contextual
token to denote a null pointer, not an actual value.

I'm not suggesting that every NULL be replaced with 0. When writing C, I
use NULL to initialise pointers. My point is that it is OK to use 0
instead of NULL in the general case, and especially in this case.



More information about the quake3 mailing list