Re: Usage of C++ NULL vs 0
On Jul 25, 3:45 pm, Matthias Buelow <m...@incubus.de> wrote:
muktipada wrote:
As a C++ developer which one we should use for pointer assignment,
NULL or 0.
For assignment, I use 0 (in both C and C++) and usually !p for
testing for a null pointer. IMHO "NULL" is ugly and probably
just a workaround left over from the days when assigning 0 to
pointers could have caused type problems.
I think you've got it backwards. C++ is a typed language, and
you should say what you mean. In particular, a conditional
should have type bool, rather than count on some obscure
implicit conversions. The use of 0 for a null pointer is a
hang-over from C, where the authors forgot to provide a proper
null pointer constant (probably because the language was
evolving from B, which didn't have a bool type---or any types,
for that matter). The next release of the C++ standard will
correct this oversight.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34