Does this code in C fall into the Undefined Behavior category?

前端 未结 4 870
余生分开走
余生分开走 2021-01-12 10:36

a is an array, foo is a function, and i is an int.

a[++i] = foo(a[i-1], a[i]);

Would

4条回答
  •  天涯浪人
    2021-01-12 11:05

    According to the C Standard (6.5.16 Assignment operators):

    Semantics

    3 ...The evaluations of the operands are unsequenced.

    Thus this statement

    a[++i] = foo(a[i-1], a[i]);
    

    results in undefined behavior.

提交回复
热议问题