3 ms·
> 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. Right, but i
by bbatha 9y ago
> 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.
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.