News for hackers. Stuff that matters.
Re:Undefined behavior in C is a reading error by tsimionescu on Friday May 21, 2021 @01:24AM (#27230782)
It's not a huge leap, but it still doesn't mean that UB by definition means that the compiler is allowed to assume UB doesn't happen. Allowing the compiler to assume this is one reasonable result of this definition (I give an example of how this reasoning works somewhere else), but it is not equivalent to the definition of UB, in principle.
Re:Undefined behavior in C is a reading error by systoll on Friday May 21, 2021 @03:40AM (#27231458)
The definition logically implies that compilers are allowed to assume UB doesn't happen. The definition is:

> undefined behavior: behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements.

With these optimisations, either:

1. The program contains no UB, the transformed code acts as expected, and the compilation is valid.

2. There's UB; the standard imposes no requirements on what behaviour that translates to; and so the transformed code is valid, regardless of what it does.

Re:Undefined behavior in C is a reading error by tsimionescu on Friday May 21, 2021 @07:44AM (#27232806)
It implies it, but they are not equivalent. Basically the common interpretation of UB is sufficient, but not necessary, given the standard.