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.SIDEEFF.2012

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

MISRA-C 2012 Rule 13.3: A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator

C90 [Unspecified 7, 8; Undefined 18], C99 [Unspecified 15; Undefined 32]

Category: Advisory

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

A function call is considered to be a side effect for the purposes of this rule.

All sub-expressions of the full expression are treated as if they were evaluated for the purposes of this rule, even if specified as not being evaluated by The Standard.

Rationale

The use of increment and decrement operators in combination with other 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 (covered by Rule 13.2).

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

Example

The expression:

u8a = u8b++

is non-compliant. The non-compliant expression statement:

u8a = ++u8b + u8c--;

is clearer when written as the following sequence:

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

The following are all compliant because the only side effect in each expression is caused by the increment or decrement operator.

x++;
a[ i ]++; 
b.x++; 
c->x++; 
++( *p ); 
*p++; 
( *p )++;

The following are all non-compliant because they contain a function call as well as an increment or decrement operator:

if ( ( f ( ) + --u8a ) == 0u ) 
{ 
}

g ( u8b++ );

The following are all non-compliant even though the sub-expression containing the increment or decrement operator or some other side effect is not evaluated:

u8a = ( 1u == 1u ) ? 0u : u8b++;

if ( u8a++ == ( ( 1u == 1u ) ? 0u : f ( ) ) ) 
{ 
}

See also

Rule 13.2