MISRA.ASSIGN.SUBEXPR.2012MISRA C 2012 Rule 13.4: The result of an assignment operator should not be usedThe result of an assignment operator is used. C90 [Unspecified 7, 8; Undefined 18], C99 [Unspecified 15, 18; Undefined 32] [Koenig 6] Category: Advisory Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationThis rule applies even if the expression containing the assignment operator is not evaluated. RationaleThe use of assignment operators, simple or compound, in combination with other arithmetic operators is not recommended because:
Examplex = y; /* Compliant */ a[ x ] = a[ x = y ]; /* Non-compliant - the value of x = y * is used */ /* * Non-compliant - value of bool_var = false is used but * bool_var == false was probably intended */ if ( bool_var = false ) { } /* Non-compliant even though bool_var = true isn't evaluated */ if ( ( 0u == 0u ) || ( bool_var = true ) ) { } /* Non-compliant - value of x = f() is used */ if ( ( x = f ( ) ) != 0 ) { } /* Non-compliant - value of b += c is used */ a[ b += c ] = a[ b ]; /* Non-compliant - values of c = 0 and b = c = 0 are used */ a = b = c = 0; See alsoRule 13.2 |