Falsehoods programmers believe about undefined behaviorUndefined behavior (UB) is a tricky concept in programming languages and compilers. Over the many years I've been an industry mentor for MIT's 6.172 Performance Engineering course, I've heard many misconceptions about what the compiler guarantees in the presence of UB. This is unfortunate but not surprising!
For a primer on undefined behavior and why we can't just "define all the behaviors," I highly recommend Chandler Carruth's talk "Garbage In, Garbage Out: Arguing about Undefined Behavior with Nasal Demons."
You might also be familiar with my Compiler Adventures blog series on how compiler optimizations work. An upcoming episode is about implementing optimizations that take advantage of undefined behavior like dividing by zero, where we'll see UB "from the other side."
Undefined behavior != implementation-defined behavior
https://predr.ag/blog/falsehoods-programmers-believe-about-undefined-behavioronewd 73 points
At least it won't start playing Doom
GCC used to start NetHack, Rogue etc. for some implementation-defined behavior
https://feross.org/gcc-ownage/?1?1zjm555 42 points
A lot of these were truly surprising, but this one:
"If the program compiles without errors then it doesn't have UB."
Someone actually believes that? UB typically results in warnings at best...
SilentXwing 7 points
Exactly. Leaving a variable uninitialize (C++ for an example) can result in a warning from the compiler, but the compiler can still compile and create an executable with UB present.
https://old.reddit.com/r/programming/comments/z6y2n5/falsehoods_programmers_believe_about_undefined