kst@aonix.com (Keith Thompson) writes: > In dewar@merv.cs.nyu.edu (Robert Dewar) writes: > > Actually, when I talked to Alex, he indicated that there were critical > > features in Ada 95 that were missing in C and C++ for this kind of > > work. In particular, he noted that C lacks a general address comparison > > operation, useful for hashing data structures, whereas Ada does have such > > an operation (in System.Storage_Elements on type Integer_Address). It is > > a bit ironic to identify this particular feature as crucial (since most > > people mistakenly think that C has such a feature and Ada doesn't!) > > Well, sort of. > > It's true that C pointer comparison is undefined unless the pointers being > compared point into the same object (or one past the end of an array). > However, any real-world C implementation isn't going to go out of its > way to make such comparisons invalid. If pointers "look like" integers > at the hardware level, pointer comparison is almost certainly going to be > implemented as integer comparison. It may be signed or unsigned, but it's > almost certainly going to be consistent within a given implementation. Since this article is posted to several different groups, including comp.lang.c++, I'd like to point out that the situation in C and in C++ is somewhat different. Keith's description is correct in the case of C. In C++, though, it's only part of the story. Pointer comparison in C++ using the < operator does work just the way that he says; C++ didn't change the meaning of the < operator. However, C++ includes another way of comparing the magnitude of two values: the standard library function object less. Operator< isn't necessarily a total ordering on pointers, but less is. To quote the draft standard (section 20.3.3): "For templates greater, less, greater_equal, and less_equal, the specializations for any pointer type yield a total order, even if the built�in operators <, >, <=, >= do not."