J
James Kuyper
I'm not sure how helpful that really is. Linearity within each
object is important, but as long as I can get a unique address for
each object (including each byte within each object), why should
I care how addresses of distinct objects relate to each other
(apart from "==" and "!=" working properly)?
The ability to meaningfully compare pointers for order, even if they're
not pointers into or one past the end of the same array, would allow you
to test whether a given pointer points within a given block of memory by
just performing two comparisons - one with each end of that block. If
all you can count on is "==" and "!=", your only choice is to iterate
over the entire block, checking each possible location within the block
for equality.
Comparisons for order that provide a consistent total ordering of all
pointers also make it possible to sort a table of arbitrary pointers,
and, for instance perform a binary search on that table to locate a
pointer in that table.
In C++, std::less<T*>(p,q) is required to return p<q, except that it is
supposed to proved a total ordering, even if < does not. I gather that
there exist platforms for which std::less(p,q) is substantially slower
than p<q, because of the hoops the C++ standard library has to jump
through in order to meet that requirement.