From C standard ISO/IEC 9899:201x 5.1.2.3p6:
The least requirements on a conforming implementation are:
- Accesses to volatile objects are evaluated strictly according to the rules of the abstract machine.
- At program termination, all data written into files shall be identical to the result that execution of the program according to the abstract semantics would have produced.
- The input and output dynamics of interactive devices shall take place as specified in 7.21.3. The intent of these requirements is that unbuffered or line-buffered output appear as soon as possible, to ensure that prompting messages actually appear prior to a program waiting for input.
This is the observable behavior of the program.
The meaning of this paragraph is quite dramatic (at least for me), the way I see it, this paragraph says that:
(1) A compiler which produce the same observable behavior, as would a fully-standard-conforming abstract machine produce, is a conforming compiler, which means that all of the other requirements and paragraphs in the standard are just extra (beside sections of volatiles and 7.21.3), for example a conforming compiler can actually break the rules of order-of-evaluations (a && b) as long as the observable behaviour (volatiles, files content and interactive output) is correct.
(2) A program that does not have volatiles, does not write to files and has no input-output interactive, is a program which actually does nothing, has no observable behaviour and can be fully optimized to, for example, two instruction of xor eax, eax than ret (x86-64 clang 7.0.0) in the main.
Am I right, or way off about this?