3 ms·
Looks like you believe in some falsehoods most programmers believe about UB. Well, you are not alone.
by marcosdumay 4y ago
Looks like you believe in some falsehoods most programmers believe about UB. Well, you are not alone.
- Georgelemental 4y agoNo, the commenter is right, at least for Rust (can't say for other languages). UB is a property of a particular execution of a program, it happens when code is executed on the abstract machine. As the blog post linked from the article (point 14, footnote 6) states: > Right now, we have the fundamental principle that dead code cannot affect program behavior.
- marcosdumay 4y agoOn C UB is a property of any code, reachable or not, just like the article's references explain. Why are people fighting this? And yes, Rust is much more reasonable about it.
- leni536 4y agoHow do you decide if i+1 is UB or not, unless the abstract machine reaches that line with a given value of i?
- marcosdumay 4y agoIf you write i+1 anywhere on your code, the compiler is free to assume i is different from the maxumim value and rewrite your code with that in mind. If you are not satisfied, you can read the article's references (there are 2 for unreacheable code). Or any article about UB here for the last 20 years.