Rule Definition
If an attempt is made to use an identifier in a preprocessor directive, and that identifier has not been
defined, the preprocessor will assume the value zero.
#ifdef, #ifndef and defined() are provided to test the existence of a macro, and are therefore excluded.
Remediation
the use of the #define directive is preferred.
Violation Code Sample
#if x < 0 // Non-compliant - x assumed to be zero as it is not defined
Fixed Code Sample
#define x 3
#if x < 0 //compliant
Reference
MISRA 2008 C++, 16-0-7: Undefined macro identifiers shall not be used in #if or #elif preprocessor directives, except as operands to the defined operator.
AUTOSAR 2014, C++. Rule M16-0-7: Undefined macro identifiers shall not be used in #if or #elif pre-processor directives, except as operands to the defined operator.
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.