The defined preprocessing directive is used in the context of #if and #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
and 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
#ifdef AN_IDENTIFIER
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
Compliant solution
#if defined X && defined Y && X > Y