分类: LINUX
2015-12-10 16:20:47
The preprocessor operator defined can be used in special constant expressions, as shown by the following syntax:
defined( identifier )
defined identifier
This constant expression is considered true (nonzero) if the identifier is currently defined; otherwise, the condition is false (0). An identifier defined as empty text is considered defined. The defined directive can be used in an #if and an #elif directive, but nowhere else.
In the following example, the #if and #endif directives control compilation of one of three function calls:
#if defined(CREDIT) credit(); #elif defined(DEBIT) debit(); #else printerror(); #endif
The function call to credit is compiled if the identifier CREDIT is defined. If the identifier DEBIT is defined, the function call to debit is compiled. If neither identifier is defined, the call to printerror is compiled. Note that CREDIT and credit are distinct identifiers in C and C++ because their cases are different.