Is it guaranteed by the C++ standard that if I have two pointers of the same type whose value is equal to nullptr, that the difference between those pointers is equal to 0?
In a pseudo-mathematical notation, does the following predicate hold true?
ForAll x ForAll y (x == nullptr)^(y == nullptr) -> (x - y == 0)
The simplest code example I can think of being:
int* x = nullptr;
int* y = nullptr;
assert(x - y == 0);
I suppose this boils down to: is it possible to have a valid implementation of the C++ standard for which there are multiple bit representations of nullptr that only compare as being equal because the equality operator does some magic?
x
andy
as "two null pointers" or "two null pointer values", rather than "two nullptr values" as you say in your question title. Being equal to something, being initialized using something, and actually being that something are all different concepts, and it's best not to mix them.nullptr
isn't just an abbreviation for "null pointer" (although of course that's the reason for the name), it's a very specific something. – Ation