3 ms·
I'm not sure if this covers C++ only, but here's what Stroustrup has to say: "In C++, the definition of NULL is 0, so there is only an aesthetic difference. I
by jimbobimbo 15y ago
I'm not sure if this covers C++ only, but here's what Stroustrup has to say:
"In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0."
- kelnos 15y agoThat definition is indeed C++-only.
- kzrdude 15y agoNot sure in which sense it is C++ only. 0 is a null pointer constant in C.
- kelnos 15y agoMy mistake. I could have sworn that only C++ defined 0 to be equivalent to a null pointer. I guess my confusion stemmed from the fact that the NULL preprocessor macro in C++ is actually defined to be just "0" (or a magical-seeming "__null" in recent versions of g++), whereas in any modern C implementation I've seen, it's "((void *)0)". Though there are cases in which passing an unadorned "0" as a null pointer can be wrong; there's a null-terminated varargs function example here: http://c-faq.com/null/null2.html http://c-faq.com/null/null2.html