3 ms·
> Maybe C allows a systems-defined behaviour to be implemented as undefined behaviour C standard distinguishes undefined behavior, unspecified behavior and imp
by zajio1am 4y ago
> Maybe C allows a systems-defined behaviour to be implemented as undefined behaviour
C standard distinguishes undefined behavior, unspecified behavior and implementation-defined behavior. The first is invalid and inconsistent, the second is valid and inconsistent, the third is valid and consistent (in scope of implementation).
It is rather hard to require invalid but consistent, as the platform itself may produce inconsistent behavior in invalid cases. So what some people want is something like - "be no more inconsistent that would be naive implementation on given platform", but that is both vague and not really useful. And while some of these undefined-based optimizations seems egregious, some are necessary in order to have reasonably performant code (e.g. keeping variable values in registers instead of propagating them from/to memory after each step).