3 ms·
> Safety, in Rust, is very well-defined; we think about it a lot. In essence, safe Rust programs cannot: > - Dereference a pointer that does not point to the t
by captainmuon 5y ago
> Safety, in Rust, is very well-defined; we think about it a lot. In essence, safe Rust programs cannot:
> - Dereference a pointer that does not point to the type the compiler thinks it points to. [...]
> - Cause there to be either multiple mutable references or both mutable and immutable references to the same data at the same time. [...]
Sometimes, I wish there was a systems language that let you exactly do that. Dereference any memory location and see what memory is there. Use a cast to reinterpret the bits. If the memory address is unmapped, then maybe just throw an exception. Allow multiple threads to fill in different spots in a huge array at the same time. Basically write C as high level assembler, like you did in the 90s.
I know -fno-strict-aliasing and some other flags can get you mostly there, but you are still violating the spec and it is at best tolerated. I also know that you loose some optimization potential, but it also reduces UB and that is a trade off you should be able to choose.
- Dylan16807 5y agoYou're effectively making every variable volatile if you do that, and you lose nearly all optimization potential.