Today I had a dispute with one of my colleagues regarding the fact that the compiler can change the semantics of a program when aggressive optimizations are activated.
My collegue states that when optimization is turned on, the compiler can reorder some instructions. So that:
function foo(int a, int b) { if (a > 5) { if (b < 6) {
Can be changed to:
function foo(int a, int b) { if (b < 6) { if (a > 5) {
Of course, in this case it does not change the general behavior of the program and does not really matter.
In my opinion, I believe that two if (condition) belong to two different points in the sequence and that the compiler cannot change its order, even if changing it will support the same general behavior.
So dear SO users, what is the truth in this regard?
c ++ optimization c compiler-construction semantics
ereOn
source share