3 ms·
> article authors are surprised the unsafe keyword is not required The often surprising part of raw pointers to system programmers newly dabbling in Rust is th
by Tuna-Fish 2y ago
> article authors are surprised the unsafe keyword is not required
The often surprising part of raw pointers to system programmers newly dabbling in Rust is that every operation on them is safe, except for deref. You can freely take addresses and do pointer arithmetic on them without having to deal with unsafe, and only have to tell the compiler that you know what you are doing when you either load or store something through them.
- zesterer 2y agoThat's... simply not true. Pointer arithmetic is not, in general, safe. Example: https://doc.rust-lang.org/std/primitive.pointer.html#method.add https://doc.rust-lang.org/std/primitive.pointer.html#method....
- gpm 2y agoEh... the ptr::add function exists if you want to make extra promises to the compiler to let it optimize better, but if you don't a safe version exists: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_add https://doc.rust-lang.org/std/primitive.pointer.html#method....