Is D's pointer subtraction more permissive than C (and C++)?

Steven Schveighoffer schveiguy at gmail.com
Fri Apr 1 20:47:21 UTC 2022


On 4/1/22 4:22 PM, Ali Çehreli wrote:
> On 4/1/22 10:39, Steven Schveighoffer wrote:
> 
>  > I don't see how the compiler/optimizer
>  > can make some other decision based on the subtraction not being between
>  > two pointers to the same block of memory.
> 
> I think this rule is related to C's accepting wildly different 
> platforms, some of which may have different kinds of memory. Two 
> pointers to different kinds of memory may not be subtracted.

Well, can the pointers be subtracted? Yes. What is the result? If they 
are in the same block, the difference in elements between two pointers. 
If they are not in the same block, anything.

This is why I don't know that it's important to avoid it.

-Steve


More information about the Digitalmars-d mailing list