Compiler control directives

The compiler control directives are used to conditionally include a header file or define macro under a specified condition.The compiler control directives are as follows:

1. #ifdef: Verifies whether or not the macro is defined. If the identifier is defined as a macro,then the compiler translates the lines of code followed by the condition.

2. #ifndef: Verifies whether or not the macro is defined. If the macro is not defined, then the #ifndef directive considers the condition to be true and executes the code statements followed by the #ifndef condition.

3. #if: Allows you to define more generalized condition by using the relational operators, such as AND(&&), OR(||). If the specified conditions are true,then the subsequent code statements are executed.

4. #ifelse: Provides the action to be performed if the condition is true or false. If the condition is true,then the code statements within the #if construct of the #ifelse directive are executed. However, if the condition is false, then the code statements within the #else construct are executed.

5. #ifelif: Allows you to take one action if there are multiple decision points. The #ifelif directive is similar to the #else directive, but it is followed by a condition. You must note that the #ifelif directive is used after the #if ,#ifdef and #ifndef directives.

Posted on by