NULL vs 0

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Tue, 21 Sep 2010 10:58:48 -0600

On 09/20/2010 11:24 PM, Amos Jeffries wrote:
> On Mon, 20 Sep 2010 17:44:17 -0600, Alex Rousskov wrote:
>> It is best to use 0 in C++ programs, but we have too much NULL-using
>> code to fight.

> Easy enough to fix with a grep/sed. Do we make '0' a coding style
> requirement?

Yes, we should if there are no objections. However, replacing current
NULLs will invalidate most pending patches. I would not do it
proactively to the old code.

> The 'NULL not always 0' is relevant to Win32 builds with MS Visual Studio
> which sets NULL == 0xCDCDCDCD (the kernels invalid RAM pattern, somewhere
> out in invalid memory space). I'm not sure if the newer VS still do this.

Squid will most likely not work if NULL is not false. 0xCDCDCDCD is not
false. Consider:

     some_pointer = some_function_that_may_return_NULL();
     if (!some_pointer)
         ...

Cheers,

Alex.
Received on Tue Sep 21 2010 - 16:58:49 MDT

This archive was generated by hypermail 2.2.0 : Wed Sep 22 2010 - 12:00:07 MDT