Title
Relational comparisons of arbitrary pointers
Status
nad
Section
7.6.9 [expr.rel]
Submitter
Herb Sutter

Created on 2007-02-26.00:00:00 last changed 109 months ago

Messages

Date: 2015-04-13.00:00:00

Additional note, April, 2015:

EWG has decided not to make a change in this area. See EWG issue 91.

Date: 2007-04-15.00:00:00

Rationale (April, 2007):

The current specification is clear and was well-motivated. Analysis of whether this restriction is still needed should be done via a paper and discussed in the Evolution Working Group rather than being handled by CWG as an issue/defect.

Date: 2022-11-20.07:54:16

The relational operators have unspecified results when comparing pointers that refer to objects that are not members of the same object or elements of the same array (7.6.9 [expr.rel] paragraph 2, second bullet). This restriction (which dates from C89) stems from the desire not to penalize implementations on architectures with segmented memory by forcing them essentially to simulate a flat address space for the purpose of these comparisons. If such an implementation requires that objects and arrays to fit within a single segment, this restriction enables pointer comparison to be done simply by comparing the offset portion of the pointers, which could be much faster than comparing the full pointer values.

The problem with this restriction in C++ is that it forces users of the Standard Library containers to use less<T*> instead of the built-in < operator to provide a total ordering on pointers, a usage that is inconvenient and error-prone. Can the existing restriction be relaxed in some way to allow the built-in operator to provide a total ordering? (John Spicer pointed out that the actual comparison for a segmented architecture need only supply a total ordering of pointer values, not necessarily the complete linearization of the address space.)

History
Date User Action Args
2015-04-13 00:00:00adminsetmessages: + msg5430
2015-04-13 00:00:00adminsetstatus: extension -> nad
2007-05-06 00:00:00adminsetmessages: + msg1512
2007-05-06 00:00:00adminsetstatus: open -> extension
2007-02-26 00:00:00admincreate