Is the left-to-right order of operations guaranteed in Java?

后端 未结 10 1388
温柔的废话
温柔的废话 2021-01-04 10:16

Consider this function:

public static final int F(int a, int b) {
    a = a - 1 + b;
    // and some stuff
    return a;
}

Is it required

10条回答
  •  猫巷女王i
    2021-01-04 10:55

    It seems to me there will always be a side effect from executing X + q - 1 When you should be executing X - 1 + q.

    When the sum x + q exceeds Bignum by 1, the left to right execution will succeed... The out of order execution will generate an overflow.

    So the out of order execution has a side-effect.

    Unless the out-of-order execution traps that overflow itself, then re-do es the calculation in the correct order when necessary to avoid the side effect.

提交回复
热议问题