this post was submitted on 28 Nov 2021
11 points (100.0% liked)
Rust Programming
8306 readers
12 users here now
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
This is a matter of correctness: does your program behave as expected? (Rust can help with this with eg. types to prevent integer overflow)
What we mean with undefined behavior is it's actually undefined. There's quite a lot of constructs you can use in C which will get compiled to different instructions by the compiler and behave in unexpected ways. Or even when compilers agree on a certain way to do it, use-after-free and other patterns can lead your program to taking unpredictable turns.
So, just because your program doesn't have undefined behavior doesn't mean it's correct. But if it's correct, it can't have any undefined behavior. If you've ever noticed how most programs written in C/C++ seem to have hard-to-reproduce bugs (eg. desktop environments) you're very likely to have encountered undefined behavior in the wild.