Hacker News new | ask | show | jobs
by cjs_2 2765 days ago
What would you suggest using instead? The actual (void *) 0?
3 comments

In C++, nullptr.
And in C?
In C, always use 0 and check for 0, it's the only safe way. For C++, it depends on the standard you're using.
Except when calling a varargs function, when you need to cast to the correct pointer type
But 0 isn't always null right?
Literal zero in a pointer context is interpreted by the compiler to mean "the null pointer." The compiler then compiles the null pointer into the code.
But then how do you get a pointer to zero (not null) in those systems?
Prior to nullptr, generally I used literal 0. In those cases which require disambiguation, I used (void * ) 0.
In C++ it'd be nullptr.