2 ms·
Rust's actually-safe pointer arithmetic is done via slices (because it's necessary to track the length): slice = &slice[1..]; It compiles to roughly `ptr+
by pornel 6y ago
Rust's actually-safe pointer arithmetic is done via slices (because it's necessary to track the length):
slice = &slice[1..];
It compiles to roughly `ptr++; len--;` and a bounds check if necessary.
`1234 as *const u8` and `ptr.offset(n)` are also safe, because Rust allows invalid/dangling pointers to exist if they're never dereferenced.
- rectang 6y agoThis answer addresses the letter of jdc's musing, but not the gist. The code that you've supplied may be "safe", but the issue is that there's no way to constrain pointer arithmetic such that the result always points at a valid location which can withstand dereferencing.