[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Re: 'NULL' versus '0'
From: |
Vadim Zeitlin |
Subject: |
[lmi] Re: 'NULL' versus '0' |
Date: |
Wed, 25 Oct 2006 17:33:14 +0200 |
Date: |
Wed, 25 Oct 2006 15:50:42 +0200 |
On Wed, 25 Oct 2006 13:27:15 +0000 Greg Chicares <address@hidden> wrote:
GC> My 'style' document makes no mention of 'NULL' (yet). I've
GC> always used '0' instead, following Stroustrup:
GC>
GC> http://www.research.att.com/~bs/bs_faq2.html#null
I've always found the logic of this answer very surprising. Indeed,
"there is only an aesthetic difference" between NULL and 0 but for me
aesthetic differences are very important -- this is the difference between
readable and maintainable code and the unreadable mess. The second part of
the answer maybe made sense many years ago when a lot of people were
transiting to C++ from C but I don't think it's applicable any more and
certainly not in a project such as LMI which was written from the ground up
in C++.
GC> However, he has changed his thinking:
GC>
GC> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf
Notice that this paper also clearly states that NULL will be defined as
nullptr in C++0x so using it now will bring the additional benefits when
the code is recompiled with a C++0x compiler or even right now if you use
gcc (which already defines NULL as __null as the same paper mentions).
IMHO this consideration, together with my belief that NULL is preferable
to 0 anyhow as it makes it absolutely clear that the code deals with
pointers whereas this is far from obvious if literal 0 is used, is a very
strong argument for using NULL in the code.
GC> May I ask you to choose a guideline for the project and
GC> change your code to follow it? Anything but 'NULL'....
Could I ask why? There must be some argument against it to compensate the
2 strong arguments in favour of using it I gave above, mustn't it? And I
certainly hope that you don't subscribe to the view that all macros are
evil because macros are just tools and, just as about anything else in C++
(templates, inheritance, ...) can be used well or badly. In this case I
don't see any problem at all with using the NULL macro as it's absolutely
unimportant that it's a macro and there are no ill side effects to worry
about.
Thanks,
VZ
- [lmi] Re: 'NULL' versus '0',
Vadim Zeitlin <=