This answer properly explains about null pointers. In the last paragraph under Null Pointers it says
If the underlying architecture has a null pointer value defined as address 0xDEADBEEF, then it is up to the compiler to sort this mess out.
Now if some architecture internally defines Null pointer value as non-zero. How can these if statements stand valid. How compiler tackles them ?
if (!pointer)
if (pointer == NULL)
if (pointer == 0)
After all when a null pointer constant is assigned to a pointer, you get a null pointer and a null pointer constant is always a 0
or a (void *)0
. Further this answer says that
So
0
is a null pointer constant. And if we convert it to a pointer type we will get a null pointer that might be non-all-bits-zero for some architectures.
I am really unable to understand how this literal 0
becomes non-all-bits-zero when initialized to a pointer. Isn't this a simple initialization ? Moreover if my null pointer value is non-zero, how can the above 3 if statements check for null pointer ? Here aren't we comparing a non-zero null pointer value with a 0
literal ?