Hacker News new | past | comments | ask | show | jobs | submit login

Oh wait, I just remembered null is normally 0 in C and C++. So probably not that if it is not 0.



If you have a page mapped at address 0, accessing address 0 is valid.


NULL isn't always the integer 0 in C. It's implementation-defined.


In every real world implementation anyone cares about, it's zero. Also I believe it is defined to compare equal to zero in the standard, but don't quote me on that.


> Also I believe it is defined to compare equal to zero in the standard, but don't quote me on that.

That's true for the literal constant 0. For 0 in a variable it is not necessarily true. Basically when a literal 0 is assigned to a pointer or compared to a pointer the compiler takes that 0 to mean whatever bit pattern represents the null pointer on the target system.


What? If you have a null pointer to a class, and try to reference the member that starts 156 bytes from the start of the class, you’ll deference 0x9c (0 + 156)


Strangely, not necessarily on every implementation on every processor.

It's not guaranteed that NULL is 0.

Still, I don't think you'd find a counterexample in the wild these days.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: