Y
Hacker News
new
|
ask
|
show
|
jobs
by
cjs_2
2933 days ago
What would you suggest using instead? The actual (void *) 0?
3 comments
CopperWing
2933 days ago
In C++, nullptr.
link
cjs_2
2933 days ago
And in C?
link
craigching
2933 days ago
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.
link
fanf2
2932 days ago
Except when calling a varargs function, when you need to cast to the correct pointer type
link
guipsp
2933 days ago
But 0 isn't always null right?
link
cjensen
2931 days ago
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.
link
guipsp
2931 days ago
But then how do you get a pointer to zero (not null) in those systems?
link
cjensen
2931 days ago
Prior to nullptr, generally I used literal 0. In those cases which require disambiguation, I used (void * ) 0.
link
Fronzie
2933 days ago
In C++ it'd be nullptr.
link