3 ms·
Are there any types of error which mighz happen in Rust but are impossible in C++?
by yoodenvranx 12y ago
Are there any types of error which mighz happen in Rust but are impossible in C++?
- Jweb_Guru 12y agoRust defines some things as undefined behavior that are not undefined behavior in C++. For example, C++ does not consider it undefined behavior when two mutable references alias the same memory. If you manage to create such a situation (using unsafe code, for example), Rust will assume that the two references cannot alias one another, and so may generate incorrect code where C++ would not.
- chrismorgan 12y agoOf course, by creating multiple mutable references to the same object by unsafe transmutation (which must be explicit, naturally), you have violated Rust’s invariants. But in safe code you cannot do that, and even doing it in unsafe code is not trivial, though it’s not excessively difficult either.