Here's something I'd love to know about undefined behavior in C: is this something specific to C, or is it something that any similar language would have to contend with? It seems like problems crop up when you combine a fairly low-level language with an emphasis on performance, a specification that explicitly calls out implementation-defined and undefined semantics, and very highly optimizing compilers. None of the…
Division by zero is UB. This lets the compiler assume it does not happen and thus it won't have to emit additional instructions to check for it. To be eliminate the check at compile to it would have to be able to infer the range of the values of the divisor. > and their compilers don't optimize as aggressively as GCC or Clang. Some languages use GCC or LLVM as optimizing backends. So they can suffer from just the sam…
Right, but it doesn't then follow that it can then "optimize" out the rest of your program. It could allow it to compile to what's expected and rely on the platform to handle corrupt program state. Which is what happens if you trigger run time UB anyway. It can also be implementation defined, because virtually all modern platforms trap on division by zero which would lead to more predictable optimizer behavior.