4 ms·
If you read my post carefully the "thinks the result would be the same" was about compiler optimization case, not processors' out-of-order execution. Take this
by conductor 10y ago
If you read my post carefully the "thinks the result would be the same" was about compiler optimization case, not processors' out-of-order execution.
Take this example:
a = 5;
b = sqrt(44);
return a * b;
If the optimizer is sure (and strict aliasing[0] also helps to be sure in many other not so obvious cases) that the sqrt function is not using the a variable then it can swap lines 1 and 2 in the generated machine code, and the result will be the same.
In your example changing lines 2 and 3 will alter the result naturally so the optimizer won't touch it.
[0] http://dbp-consulting.com/tutorials/StrictAliasing.html http://dbp-consulting.com/tutorials/StrictAliasing.html