5 ms·
The thing is the guaranteed semantics are something totally different than what you usually expect when looking at the code. That is why the term "observable" i
by Sankozi 3y ago
The thing is the guaranteed semantics are something totally different than what you usually expect when looking at the code. That is why the term "observable" is often introduced when explaining how optimizer works (or can work).
The example is wrong because compiler is allowed to do optimization in such context not due to the undefined behavior. The "within-thread as-if-serial" guarantees are still preserved and optimization still can be done even if undefined behavior is removed from the example.