C++ Logo

std-discussion

Advanced search

Hostile implementation of strict total order of pointers

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Sat, 22 Jul 2023 19:40:05 +0100
Hi,

Given these two arrays, each being a complete object:

int a[2];
int b[2];

The partial ordering of the addresses (defined by the operator <) of
the int objects within is:

1. &a[0] < &a[1]
2. &b[0] < &b[1]

A hostile strict total order that is consistent with this is
&a[0] < &b[0] < &a[1] < &b[1].

Is there wording that prevents the implementation defined strict total
order to manifest like this?

One problem with this is that std::less is commonly used to check if a
given pointer points within a range. If such a manifestation is
possible then such usages are incorrect (or at least theoretically not
portable).

Cheers,
Lénárd

P.S. Someone pointed this out to me on the #include <C++> discord.

Received on 2023-07-22 18:40:11