Robert Dewar <[EMAIL PROTECTED]> writes: | Paolo Carlini wrote: | | >chris jefferson wrote: | > | > | >>>Right, but that's the point. "doing arithmetic on arbitrary pointer" | >>>values is | >>>not defined, it is not even defined to compare two pointers pointing | >>>to two | >>>different objects. | >>> | >>> | >>While that is true according to the standard, I believe that on most | >>systems you can compare any two pointers. In particular, the C++ | >>standard does require a total ordering on pointers, and at the moment | >>that is implemented for all systems by just doing "a < b" on the two | >>pointers. | >> | >Humpf! Can people please cite exact paragraphs of the relevant | >Standards? Otherwise, I think we are just adding to the confusion. For | >example, in my reading of C99 6.5.9 and C++03 5.10 pointers *can* be | >compared for equality and discussing separately and correctly relational | >operators and equality operators is not a language-lawyer-ism, is *very* | >important for its real world implications. But this is only an example... | > | >Paolo. | > | Surely pointers can be compared for equality (it is fine to see if a | pointer is pointing | to something). The discussion about pointer comparison across objects is wrt | expecting any kind of ordering relationshiop.
What Chris' meant was that the C++ standard requires std::less<T*> to provide a total ordering on pointers -- there is no requirement that they should be same-object-related. The current implementation shipping with GCC is to simply use operator<, based on the assumption that GCC uses the "obvious" model. -- Gaby