K
Keith Thompson
The key is in the "or to a pointer to void" words in A7.10. It means
you can compare a pointer to an object and a pointer to non-object for
equality, so the restriction that both pointers must point inside the
same object no longer applies. It's still not immediately obvious that
you can compare for equality object pointers that point to different
objects, but, since p == (void *)q is allowed regardless of where q
points (the text under discussion doesn't impose restrictions on the void
pointer operand), it follows that p == q should be valid, too (assuming
that the types of p and q allow direct comparison for equality).
Sorry, I'm not convinced. Someone who hasn't assumed that p == q is
valid is not likely to infer it from the pointer-to-void rule. If the
"additional possibilities" clause is meant to be exhaustive, it's
pretty clear (to me) that it *deosn't* cover p == q, where p and q are
pointers to distinct non-adjacent objects; neither p nor q is a
pointer to void.
Given that p == (void*)q is valid, it certainly makes sense that p == q
*should* be valid, but it's not stated, and there are too many other
places in the language where the "it makes sense that it should be
valid" rule breaks down.