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.STMT.COND.NOT_BOOLEAN.2012

The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type.

MISRA C 2012 Rule 14.4: The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

The controlling expression of a for statement is optional. The rule does not require the expression to be present but does require it to have essentially Boolean type if it is present.

Rationale

Strong typing requires the controlling expression of an if statement or iteration-statement to have essentially Boolean type.

Example

int32_t *p, *q;

while ( p )                /* Non-compliant - p is a pointer */ 
{ 
}  

while ( q != NULL )       /* Compliant                        */
{
}

while ( true )            /* Compliant                        */ 
{
}

extern bool_t flag;

while ( flag )             /* Compliant                       */ 
{
}

int32_t i;

if ( i )                   /* Non-compliant                   */ 
{
}

if ( i != 0 )              /* Compliant                       */ 
{ 
}

See also

Rule 14.2, Rule 20.8