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.ELIF.COND.NOT_BOOL.2012

#elif condition is not 0 or 1

MISRA C 2012 Rule 20.8: The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

This rule does not apply to controlling expressions in preprocessing directives which are not evaluated. Controlling expressions are not evaluated if they are within code that is being excluded and cannot have an effect on whether code is excluded or not.

Rationale

Strong typing requires the controlling expression of conditional inclusion preprocessing directives to have a Boolean value.

Example

#define FALSE 0 
#define TRUE  1

#if FALSE            /* Compliant                              */ 
#endif

#if 10               /* Non-compliant                          */ 
#endif

#if ! defined ( X )  /* Compliant                              */ 
#endif

#if A > B            /* Compliant assuming A and B are numeric */ 
#endif

See also

Rule 14.1