Quantcast
Channel: How compiler handles a non-zero null pointer value in C? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How compiler handles a non-zero null pointer value in C?

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>