4 ms·
I disagree. nullptr is directly convertable to a boolean 0: #include <stdio.h> int main(int argc, char *argv[]) { printf("%d\n", nullptr == 0); return
by edoo 8y ago
I disagree. nullptr is directly convertable to a boolean 0:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d\n", nullptr == 0);
return 0;
}
- masklinn 8y ago1. You're comparing a null pointer literal with a null pointer constant. You're literally comparing two things guaranteed to be equal. How, exactly, is it surprising that they do? Did you even attempt to understand what I wrote? 2. The specific implementation you have on hand could use zero-valued null pointers, I'm telling you what the standard doesn't say, confirmed by the C FAQ: http://c-faq.com/null/varieties.html http://c-faq.com/null/varieties.html http://c-faq.com/null/confusion4.html http://c-faq.com/null/confusion4.html http://c-faq.com/null/machexamp.html http://c-faq.com/null/machexamp.html 3. The null pointer is not "directly convertible to a boolean 0", it's the literal 0 which expresses a null pointer: http://c-faq.com/null/ptrtest.html http://c-faq.com/null/ptrtest.html
- edoo 8y agoI see what you are saying. I mean zero as null constant. I've never even seen anyone try to assign a null value with some integer zero at some memory address. Using the NULL constant in C/C++ is near effortless and 0 just works no matter what the underlying implementation is doing. So for all intents and purposes nullptr is just a casted NULL (0) constant.