defined preprocessing directive is used in the context of
#elif expressions to see whether a
given identifier has been defined as a macro. It returns a value of 0 (false) or 1 (true), and has two valid forms,
defined ( IDENTIFIER ). Since it is essentially a macro existence check, it cannot take expressions as arguments.
Note that since
#if defined AN_IDENTIFIER
is equivalent to
defined is most useful when there are multiple arguments to check, E.G.
#if defined AAA || defined BBB
Noncompliant Code Example
#if defined ( X > Y ) // Noncompliant; expressions not allowed
#if defined X && defined Y && X > Y
- MISRA C:2004, 19.14 - The defined preprocessor operator shall only be used in one of the two standard forms.
- MISRA C++:2008, 16-1-1 - The defined preprocessor operator shall only be used in one of the two standard forms.