[previous] MISRA-C:2004  Rule  12.13:  (Advisory) [next] The increment (++) and decrement (--) operators should not be mixed with other operators in an expression.
It is the intention of the rule that when the increment or decrement operator is used, it should be the only side effect in the statement. The use of increment and decrement operators in combination with other arithmetic operators is not recommended because:

* It can significantly impair the readability of the code.

* It introduces additional side effects into a statement with the potential for undefined behaviour.

It is safer to use these operations in isolation from any other arithmetic operators.

For example a statement such as the following is not compliant:

u8a = ++u8b + u8c--;      /* Not compliant */

The following sequence is clearer and therefore safer:

++u8b;
u8a = u8b + u8c;
u8c--;


QAC messages that encompass this guideline:

3440 Using the value resulting from a ++ or -- operation.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents