From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: Matt Austern Subject: Re: OO, C++, and something much better! Date: 1997/01/10 Message-ID: #1/1 X-Deja-AN: 209065851 references: organization: SGI newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-10T00:00:00+00:00 List-Id: 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."