Why isn't NULL defined as (void*)0 instead of just 0?
Wouldn't that make everyone happy?
Why isn't NULL defined as (void*)0 instead of just 0?
Wouldn't that make everyone happy?
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
No, a null pointer can be any value. However, when compared to another null pointer or the literal 0 (or 0L or something) then it must be equal. When compared to reinterpret_cast<T*>((int)0) then the result is undefined, although all implementations will say it is equal. The point is, C++ does not mandate anything about the implementation representation of pointers.
Last edited by King Mir; 12-20-2009 at 09:28 PM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Technically, NULL has to evaluate to zero. I quoted the C++ standard in post #3. In the case you described, it would simply be a non-zero value as an address, but it nonetheless evaluates to zero.Originally Posted by abachler
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Taken directly out of ..stdio, I think.Code:#ifdef _cplusplus #define NULL 0 #else #define NULL (void*)0 #ifdef
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."