3 ms·
This isn’t entirely untrue in theory, but in practice it is. Compilers optimize under the assumption that undefined behavior never occurs, and the standard is w
by yoklov 8y ago
This isn’t entirely untrue in theory, but in practice it is. Compilers optimize under the assumption that undefined behavior never occurs, and the standard is written with this assumption. Any conforming compiler is free to break code that relies on this.
Typically, behavior that reasonably may vary from compiler/machine is considered implementation defined, and not undefined.
- kazinator 8y ago> Any conforming compiler is free to break code that relies on this. Ah, but, for example, __attribute__((packed)) is undefined behavior; is the compiler free to break that? This "free to break" is a juvenile fiction based on the idea that the only document that applies is ISO C; there is no other contract or promise between user and implementor.
- sanxiyn 8y agoGCC documentation is another such contract, which provides -fwrapv. If you want -fwrapv, use -fwrapv.