3 ms·
Isn’t var ptr: [*]u8 = @ptrCast([*]u8, &slice[0]); the same as var ptr = slice.ptr; ? Or am I missing something
by pyrolistical 4y ago
Isn’t
var ptr: [*]u8 = @ptrCast([*]u8, &slice[0]);
the same as
var ptr = slice.ptr;
?
Or am I missing something
- WalterBright 4y agoThe `slice.ptr` version is allowed in D, but `&slice[0]` is preferred because that comes with a check that the slice has a non-zero length and the pointer will actually point to something valid. That's why the former is allowed in @system code, and the latter is used in @safe code.
- nektro 4y agoyes it would be the same