Two Equal Signs in One Line?

后端 未结 10 887
北荒
北荒 2020-12-06 04:58

Could someone please explain what this does and how it is legal C code? I found this line in this code: http://code.google.com/p/compression-code/downloads/list, which is a

10条回答
  •  隐瞒了意图╮
    2020-12-06 05:37

    That is just chaining of the assignment operator. The standard says in 6.5.16 Assignment operators:

    An assignment operator shall have a modifiable lvalue as its left operand. An assignment operator stores a value in the object designated by the left operand. An assignment expression has the value of the left operand after the assignment, but is not an lvalue. The type of an assignment expression is the type of the left operand unless the left operand has qualified type, in which case it is the unqualified version of the type of the left operand. The side effect of updating the stored value of the left operand shall occur between the previous and the next sequence point.

    So you may do something like:

    a=b=2; // ok
    

    But not this:

    a=2=b; // error
    

提交回复
热议问题