4 ms·
For example, as mentioned in another comment, by making all read and write `volatile`, that way, dangling pointer and out of bounds are "defined" to be memory c
by isomel 5y ago
For example, as mentioned in another comment, by making all read and write `volatile`, that way, dangling pointer and out of bounds are "defined" to be memory corruption or crash, and not the compiler optimizing the code in a way that the programmer did not enticipate.
- znpy 5y agoWouldn't that bring a performance penalty though?
- __d 5y agoYes. But the current trade-off (performance always wins) means that kernels and other embedded-style programs cannot rely on the compiler doing the "reasonable" thing for UB because it's explicitly allowed to do whatever it wants (which is generally, try for better performance). For kernel-style work, slightly lower performance but predictable/defined behavior for some of what is currently UB, makes life much simpler.
- Ar-Curunir 5y agoYou don’t need to do what youre saying for that; Rust provides a way to get both performance and safety