6 ms·
Oh wait, I just remembered null is normally 0 in C and C++. So probably not that if it is not 0.
by blirio 2y ago
Oh wait, I just remembered null is normally 0 in C and C++. So probably not that if it is not 0.
- taspeotis 2y agoWhat? 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)
- emmelaich 2y agoStrangely, 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.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- chongli 2y agoNULL isn't always the integer 0 in C. It's implementation-defined.
- loeg 2y agoIn 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.
- tzs 2y ago> 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.
- cmpxchg8b 2y agoIf you have a page mapped at address 0, accessing address 0 is valid.