AutosarC++18_10-M5.2.10

The increment (++) and decrement (–) operators should not be mixed with other operators in an expression

Required inputs: IR

Rationale

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 operators in isolation from any other arithmetic operators.

Example

A statement such as the following is non-compliant:

u8a = ++u8b + u8c--;   // Non-compliant

The following sequence is clearer and therefore safer:

++u8b; 
u8a = u8b + u8c;
u8c--;
See also

ISO/IEC 14882:2003 §5.2.6, §5.3.2

Note

For legal reasons, this rule’s description is not part of the public documentation.