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 21:07:31 +0000
Hi,

On 2 December 2022 20:49:52 GMT, David Carter via Std-Discussion <std-discussion_at_[hidden]> wrote:
>> layout stack variables as you are not allowed to compare addresses of
>them.
>
>This is a very interesting point. When I raised a question earlier this
>year about std::thread behaviour differences between heap and stack objects
>I was told that the C++ standard made no distinction between the two types
>of memory. In this particular case we seem to be saying that stack
>variables in particular require special rules. Is that in effect written
>in the standard somewhere for relational operators on pointers?
>
>It is my view that there are potentially many contexts where stack vs heap
>is not only relevant but critical and that the standard should not be
>silent about them.

There is no special rule. You are not allowed to compare pointers coming from two distinct "complete objects". These objects can be each automatic variables (stack) or dynamically allocated (heap) independently from each other.

Cheers,
Lénárd

Received on 2022-12-02 21:07:36