C++ Logo

std-discussion

Advanced search

Re: Relational operators with using pointers.

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 2 Dec 2022 10:31:31 +0100
czw., 1 gru 2022 o 18:27 Edward Catmur via Std-Discussion
<std-discussion_at_[hidden]> napisał(a):
>
> On Thu, 1 Dec 2022 at 16:58, Vladimir Grigoriev via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>
>> It is unclear why such a difference between C and c++ was introduced.
>
>
> Yes. If it helps, the difference has existed since standardization: the comparison is undefined in C89 and unspecified in C++98, so it might be tricky to discover the rationale.
>
> Perhaps you could ask SG22 whether they know the cause of the divergence, and whether they're interested in resolving it.
>

This could be required by segmented memory and Far Pointer in 16-bit
architectures.
Another could be freedom for compilers how they will layout stack
variables as you are not allowed to compare addresses of them.


>> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>>
>>
>>
>> Среда, 30 ноября 2022, 22:46 +03:00 от Jens Maurer via Std-Discussion <std-discussion_at_[hidden]>:
>>
>>
>>
>> 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
>>
>> --
>> Std-Discussion mailing list
>> Std-Discussion_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>>
>>
>> --
>> Std-Discussion mailing list
>> Std-Discussion_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2022-12-02 09:31:40