Why is f(i = -1, i = -1) undefined behavior?

前端 未结 11 1661
再見小時候
再見小時候 2020-12-04 05:28

I was reading about order of evaluation violations, and they give an example that puzzles me.

1) If a side effect on a scalar object is un-sequenced r

11条回答
  •  情深已故
    2020-12-04 05:56

    Actually, there's a reason not to depend on the fact that compiler will check that i is assigned with the same value twice, so that it's possible to replace it with single assignment. What if we have some expressions?

    void g(int a, int b, int c, int n) {
        int i;
        // hey, compiler has to prove Fermat's theorem now!
        f(i = 1, i = (ipow(a, n) + ipow(b, n) == ipow(c, n)));
    }
    

提交回复
热议问题