Assignment operator sequencing in C11 expressions

前端 未结 3 1905
既然无缘
既然无缘 2020-12-03 11:40

Introduction

The C11 standard (ISO/IEC 9899:2011) has introduced a new definition of side effect sequencing within an expression (see related question). The se

3条回答
  •  借酒劲吻你
    2020-12-03 12:16

    The standard stipulates for assignment (6.5.16) as you are citing correctly

    The side effect of updating the stored value of the left operand is sequenced after the value computations of the left and right operands.

    (The increment operator is not different, it is just an assignment in disguise)

    This means that there are two value computations (left and right) and the side effect of the assignment is then sequenced after these. But it is only sequenced against the value computations, not against the side effects that these may have. So at the end we are faced with two side effects (of the = operator and the ++ operator) that are not sequence with respect to each other.

提交回复
热议问题