News for hackers. Stuff that matters.
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.