← Back to context

Comment by rocqua

3 years ago

A quote from the C standard:

"However, if any such execution contains an undefined operation, this International Standard places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation)."

Quote found here: https://devblogs.microsoft.com/oldnewthing/20140627-00/?p=63...

It seems that the standard explicitly disagrees with you.

The "[...] executing that program with that input [...]" part maybe could be read as making it specific to a given UB triggering execution; but I'm no language lawyer :).

  • True, only executions of a program that exhibit undefined behavior are affected. But the moment it is clear a program will exhibit undefined behavior, the compiler is already allowed to do whatever it wants. So if 20 lines below an important function call you will certainly call a function that will certainly cause undefined behavior, the important function call can be already be left out.

    • And the compiler could insert additional side effect free computations ahead of time to detect if an execution will hit UB later on.