Re: [PATCH] Replace NULL symbol with 0



Tomasz Kupczyk <kupczyk tomasz gmail com> a écrit:

> Hello all,

Hello Tomasz.  :-)

> I'm new on the Nemiver mailing list,

You are welcome!

> I haven't written any code in Nemiver yet, so maybe I shouldn't
> comment on the code here,

I disagree.  You are free to comment here, no matter who you are.  I for
one am always interested in technical matters related to Nemiver.  :-)

> wondering what is the idea behind changing all NULL's to 0's?
>
> As far as I know NULL equal to 0 is platform dependent, but on most
>platforms probably it's indeed 0.

The C++ specification says, in [conv.ptr]/1:

    A null pointer constant is an integral constant expression (5.19)
    prvalue of integer type that evaluates to zero

So, the constant 0 is a perfectly valid platform independent null
pointer constant in C++, unlike in C.

When you use g++, NULL is a macro defined to __null, which is a special,
g++ specific symbol that does the right thing, i.e, it evaluates to
zero.

Furthermore, NULL being a macro, if you want to see its integral
representation in a debugger, you have to have to e.g, have some arcane
compiler flag enabled, as just -g is not enough.  If you use zero, in
the debugger, you know easily that it is zero.

> Different thing is that IMO using NULL makes sometimes code easier to
> read,

I understand that conveying the idea that "this is a null pointer
constant" is more maintainable (as in, "it tells a better story to the
reader's mind") than just 0, when using a context that expects a
pointer.  But NULL is not necessarily correct.  That why c++0x
introduces the null pointer constant nullptr, of type nullptr_t.

For now, my take was that it's less confusing to separate NULL which
originates from C and which is platform dependant, as you pointed out,
from 0.  And use 0 instead.  When you are used it, it zero can also tell
a nice story to the reader's mind, I believe.  :-)

I am happy to let pieces of code that are compiled with a C compiler use
NULL.

> and for example if in the future compilers will start to enforce
> semantically null pointers being really NULL then all 0's will need to
> be turned into NULL's once again.

I don't understand this.  nullptr of c++0x comes with an implicit
conversion that can convert it to 0.  So using 0 will still work in
c++0x.

-- 
		Dodji


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]