February 16, 2023 Re: Comparing pointers in C and D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Olivier Pisano | On 16.02.23 07:42, Olivier Pisano wrote:
> On Thursday, 16 February 2023 at 06:37:54 UTC, Olivier Pisano wrote:
>> If I change the variable types by arrays of 1 int, I get the same result :
>>
>> https://godbolt.org/z/YWTvTPr4W
>>
>> You are right, it is certainly a UB, but it seems that the GCC optimizer treats scalars and arrays the same way, as soon as it can statically deduce the arithmetic goes past the end of the object memory space.
>
> And now I start wondering how can STL algorithms even work since the end iterator is past the last element. Gosh...
You shouldn't run into this kind of issue as long as you only compare iterators from the same container, don't go past the end by more than one element and don't dereference past-the-end iterators.
|
Copyright © 1999-2021 by the D Language Foundation