Hi. For anyone still interested, here's my humble conclusion (not thee
conclusion, just my conclusion
):
Eventually C++ will have a constant called nullptr. At that time,
that's the thing to use for null pointer values.
Until then, 0 is preferred over the NULL macro since some third party
library could easily provide a NULL macro under the sheets that sets
NULL to (void *)0, as per C. This could inadvertently redefine one's
own NULL that is set to 0. One would hope that a "macro redefinition"
warning would occur in that case, but even if it does, confusion is
bound to occur. Regardless of the macro redef warning, in C++, a type
error would occur if (void *)0 snuck in and was set to a type other than
(void *). I think that's what BS was referring to in regards to C++ and
type checking. Using the constant 0 solves these problems.
Note that BS's recommendation to use const int NULL = 0 doesn't work.
If a NULL macro is being included (as it will be under the sheets in
most cases), the preprocessor will change const int NULL = 0 to
something like"const int 0 = 0" or "const int (void *)0 = 0", neither of
which compiles.
Also, according to the C++ standard, when 0 is set into a pointer, it
does not result in address 0 being generated in the object code. It
actually will result in the target system's null pointer value to be
generated, which may or may not be 0. So according to the C++ standard,
the constant 0, when used as a pointer rvalue, is really an abstraction
for null pointer.
Lastly, when using 0 as a null pointer, one must heed Steve Meyers
recommendation to not allow the same method to be overloaded with an
integer and a pointer. If you do that, programmer confusion will occur
if a 0 constant is used as a parameter (the C++ program will not be
confused--it will assume an integer--but the programmer will easily be
confused by the resulting behavior if he were assuming the parameter to
be treated as a null pointer).
Thanks to all for your varied and interesting thoughts. It's what makes
these newsgroups invaluable.
See ya,
Ken