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.ASSIGN.SUBEXPR.2012

MISRA C 2012 Rule 13.4: The result of an assignment operator should not be used

The 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

Amplification

This rule applies even if the expression containing the assignment operator is not evaluated.

Rationale

The use of assignment operators, simple or compound, 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 making it more difficult to avoid the undefined behaviour covered by Rule 13.2.

Example

x = 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 also

Rule 13.2