NULL vs 0

2010-09-21 Thread Alex Rousskov

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.


Re: NULL vs 0

2010-09-21 Thread Robert Collins
On Wed, Sep 22, 2010 at 4:58 AM, Alex Rousskov
rouss...@measurement-factory.com wrote:
 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)
        ...

When compilers do that, they also translate the if expression appropriately.

But they are also meant to handle NULL vs 0 transparently in that case, AIUI.

-Rob


Re: NULL vs 0

2010-09-21 Thread Alex Rousskov

On 09/21/2010 12:49 PM, Robert Collins wrote:

On Wed, Sep 22, 2010 at 4:58 AM, Alex Rousskov
rouss...@measurement-factory.com  wrote:

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)
...


When compilers do that, they also translate the if expression appropriately.
But they are also meant to handle NULL vs 0 transparently in that case, AIUI.


Scary but good to know, thank you. Looks like 0xCDCDCDCD, if used as a 
pointer, becomes false in that case!


Alex.