2.12.2013

Preprocessor directives

The #if directive can be used to test whether an expression evaluates to a nonzero value or not. If the result of the expression is nonzero, then subsequent lines upto a #else, #elif or #endif are compiled, otherwise they are skipped.

Syntax of #if directive as:

#if LABEL == 10
     statement 1;
     statement 2;
#else
     statement 3;
     statement 4;
     statement 5;
#endif


If we so desire, we can have nested conditional compilation directives.


#undef directive

Sometimes, it may be desirable to cause a defined name to become 'undefined'. This can be accmplished by means of the #undef directive.
Syntax: #undef macro_temp_name
example: #undef TEST


#pragma Directive

This is a special directive that we use to turn on or off certain features. Pragma vary from one compiler to another.
Turbo c/c++ compiler has got a pragma that allows you to suppress warnings generated by the compiler.
Some pragmas directives as following:
  • #pragma startup and #pragma exit
  • #pragma warn

No comments:

Post a Comment