Should (p - q) be disallowed in @safe code?
Walter Bright
newshound2 at digitalmars.com
Thu Jan 1 17:18:59 UTC 2026
On 1/1/2026 7:18 AM, Timon Gehr wrote:
> In C, subtracting pointers to different memory objects is undefined behavior,
> hence side-effecting.
>
> Subtracting pointers can be `@safe` iff it is always defined behavior. (Even if
> the defined behavior is to yield a nonsense value.)
Getting a nonsense value is memory safe, but is almost certainly a bug.
> I am not sure how GDC and LDC are currently treating this.
Since the same front end is used, I'd be surprised if they behaved differently.
More information about the Digitalmars-d
mailing list