Why isn't NULL defined as (void*)0 instead of just 0?
Wouldn't that make everyone happy?
Printable View
Why isn't NULL defined as (void*)0 instead of just 0?
Wouldn't that make everyone happy?
In C++? Honestly?
void* is not implicitly convertible to T* in C++.
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.
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.Quote:
Originally Posted by abachler
Taken directly out of ..stdio, I think.Code:#ifdef _cplusplus
#define NULL 0
#else
#define NULL (void*)0
#ifdef