Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.INCR_DECR.OTHER

Increment or decrement operator is mixed with other operators in expression.

MISRA-C Rule 12.13 (advisory): 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--;

MISRA-C++ Rule 5-2-10 (advisory): The increment (++) and decrement (--) operators should not be mixed with other operators in an expression.

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--;