C++ Logo

std-discussion

Advanced search

Re: Relational operators with using pointers.

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Fri, 02 Dec 2022 17:51:32 +0000
Hi,

On 2 December 2022 17:06:31 GMT, Edward Catmur via Std-Discussion <std-discussion_at_[hidden]> wrote:
>
>> Another could be freedom for compilers how they will layout stack
>> > variables as you are not allowed to compare addresses of them.
>
>
>I don't think undefined vs. unspecified makes much of a difference here;
>the compiler could just always return false to every comparison between
>pointers to automatic variables and you wouldn't be able to learn anything
>about the layout.

I don't think this is feasibly implementable. Consider `identity(&a) < identity(&b)`, where `identity` is opaque to the compiler.

Having said that an unspecified comparison still doesn't restrict the stack layout in any way.

Cheers,
Lénárd

Received on 2022-12-02 17:51:41