Hacker News new | ask | show | jobs
by pyrolistical 1203 days ago
Isn’t

    var ptr: [*]u8 = @ptrCast([*]u8, &slice[0]);
the same as

    var ptr = slice.ptr;
?

Or am I missing something

2 comments

The `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.
yes it would be the same