Challenge: write a reference counted slice that works as much as possible like a built-in slice
Elronnd
elronnd at elronnd.net
Tue Dec 14 06:38:53 UTC 2021
On Tuesday, 14 December 2021 at 06:27:27 UTC, Elronnd wrote:
> I think it would be reasonable to define provenance semantics
> which permit you to derive a mutable pointer from an immutable
> one
Simple example:
struct S { immutable float x; int y; }
S a;
immutable float* x = &a.x;
int y = *cast(int*)(cast(ubyte*)&x + (S.y.offsetof -
S.x.offsetof))
above should be UB if (cast(ubyte*)&x + (S.y.offsetof -
S.x.offsetof)) does not actually point to mutable memory. This
is subtly different from:
int x;
const int *p = &x;
*cast(int*)p = 5;
but still similar enough to warrant concern; which is why I think
it would also be reasonable to make the former form illegal.
More information about the Digitalmars-d
mailing list