6.5.16 assignment operator
Grammar
1,assignment-expression:
conditional-expression
unary-expression assignment-operator assignment-expression
Assignment-operator: one of the following
= *=/=%= + = = <<= >>= &= ^= |=
Constraints
2, an assignment operator should have a modifiable left value as its left operand.
Semantic
3, an assignment operator stores a value in an object that is assigned by the left-hand operand. An assignment expression that has the value of the left operand after the assignment, [Note: Allows the implementation to read this object to determine the value, but does not require this, even if the object is a volatile-qualified type. ] But not a left-hand value. The type of an assignment expression is the type of the left operand, which is available after an lvalue conversion. The order of the side effects of the values stored in the left operand is updated after the value of the left and right operands is computed. Operands are calculated without order.
6.5.16.1 Simple Assignment
Constraints
1, to abide by one of the following rules: [Note: For these asymmetric occurrences of the type qualifier is due to change the lvalue to "value of expression" and remove any type qualifier (specified in 6.3.2.1) is applied to the type category of the expression (for example,int volatile * Const Removes the const, but does not remove the volatile). ]
--The left operand has an atomic, qualified, or unqualified arithmetic type, while the right operand has an arithmetic type;
--The left operand has an atomic, qualified, or unqualified version of a struct or union type that is compatible with the right operand;
--The left operand has an atomic, qualified, or unqualified pointer type, and (given the type that the left operand will have after the Lvalue conversion) two operands have pointers to compatible types of qualified or unqualified versions, and the type pointed to by the left operand has all qualifiers for the type pointed to by the right value.
--The left operand has an atomic, qualified, or unqualified type, and one of the operands is a pointer to an object type, and the other is a pointer to a qualified or unqualified version of void . The type pointed to by the left operand has all qualifiers of the type pointed to by the right operand.
--The left operand is an atomic, qualified, or unqualified pointer, while the right operand is a null pointer constant;
--The left operand has an atomic, qualified, or unqualified _bool, while the right operand is a pointer.
Semantic
2. In simple assignment (=), the value of the right operand is converted to the type of the assignment expression, and the value in the object assigned by the left operand is replaced.
3. If a value in one object is being read from another object and the two overlap in either form, then the overlap should be accurate, and two objects should have a qualified or unqualified version of a compatible type; otherwise, the behavior is undefined.
4, Example 1 in the following program fragment
int f (void); Char C; /* */if((c = f ()) ==-) /** /
The int value returned by the function can be truncated, when stored in char , and then converted back to the int width before the comparison. In an implementation where its "trivial"char has the same scope as unsigned char (and Char is narrower than int ), then the conversion result cannot be a negative number, The operands of this comparison may never be compared to equal. Thus, for full portability, the variable C should be declared as int.
5, Example 2 in the following program fragment:
Char C; int i; Long = (c =i);
The value of I is converted to the type of the assignment expression c = i , which is the char type. The value of the expression enclosed in parentheses is then converted to the type of the outer assignment expression, that is, the long int type.
6, example 3 consider the following program fragment
Const Char * *CPP; Char *p; Const Char ' A ' = &p; // violated the constraint *cpp = &c; // effective 0; // effective
The first assignment is unsafe because it may allow the following valid code to attempt to change the value of the const object C .
6.5.16.2 Compound Assignment
Constraints
1.
ISO/IEC 9,899:2011 clause 6.5.16--assignment operator