C++ Logo

std-discussion

Advanced search

Re: Relational operators with using pointers.

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Wed, 30 Nov 2022 20:45:50 +0100
On 30/11/2022 20.30, Vladimir Grigoriev via Std-Discussion wrote:
> In the C Standard there is explicitly written that when two pointers do not point to elements of the same array (including the element or one pass the last element) the behavior is undefined:
>
> «In all other cases, the behavior is undefined.»

> However in the C++ 20 Standard I do not see such a phrase. So is the behavior is undefined or unspecified when there are compared two pointers to different objects that are not elements of the same array. as for example
>
> &x < &y

See expr.rel p5. In this case, neither pointer is required to compare
greater than the other by p4, so the result of the relational operators
is unspecified.

Jens

Received on 2022-11-30 19:45:55