3 ms·
Note that `unsafe` code blocks (or having some unsafe primitives) fundamentally results in some kind of UB in the language as a whole, and you totally can creat
by eddyb 8y ago
Note that `unsafe` code blocks (or having some unsafe primitives) fundamentally results in some kind of UB in the language as a whole, and you totally can create tons of problems from it, since the rest of the language has invariants it can't itself violate, but the unsafe code can (potentially much easier than C, if there are more invariants) - that is the "UB", and the invariants that can be violated are what the compiler optimizes based on.
Lest we forget, any language with a C FFI capability must have some notion of UB, because the FFI effectively includes the C code in its own semantics (unless fully sandboxed, which may be too expensive to be done).
- pjmlp 8y agoTrue, but they are quite easy to track down. In systems like Unisys ClearPath, you can even configure the system such that only admins can execute applications with unsafe blocks. In C any line of code, if care is not taken to use the correct compiler flags, can be a possible source of UB.
- eddyb 8y agoIndeed. Only wanted to point out that their optimizations also rely on UB, so they're bad examples for specifically "optimizing without relying on UB".
- umanwizard 8y ago> In C any line of code, if care is not taken to use the correct compiler flags, can be a possible source of UB. What do you mean?
- pjmlp 8y agoYou need to turn on all warnings as errors, static analysers and pedantic modes depending how each compiler allows them. ANSI C11 has 200 documented cases of UB, and each compiler might have additional cases, are you sure you can know all of them by heart while looking at a random line of C code?