C and C++


LANG.PREPROC.NBPE : Non-Boolean Preprocessor Expression

Summary

The controlling expression of a preprocessor #if or #elif directive is evaluated, and has a value other than 1 (one) or 0 (zero).

Controlling expressions that are not evaluated do not have any influence on the program and so do not trigger warnings of this class.

Properties

Class Name Non-Boolean Preprocessor Expression
Significance style
Mnemonic LANG.PREPROC.NBPE
Categories
MisraC2023 MisraC2023:20.8 The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1
Misra2012 Misra2012:20.8 The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1
POW10 POW10:8 Limit the use of the preprocessor to file inclusion and simple macros.
JPL JPL:20 Make only very limited use of the C pre-processor.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Non-Boolean Preprocessor Expression"

Example

#define ONE 1
#define TWO 2

#if TWO           /* 'Non-Boolean Preprocessor Expression' warning issued here. */
/* ... */
#endif 

#if TWO > ONE                 /* Boolean */
/* ... */
#endif 


#if !ONE                      /* Boolean */
/* ... */
#if TWO                       /* Not evaluated: !ONE always evaluates to FALSE. */
/* ... */
#endif
/* ... */
#endif 

#if ONE                       /* Boolean */
/* ... */
#elif TWO                     /* Not evaluated: ONE always evaluates to TRUE. */
/* ... */
#endif

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.