Thursday, 31 August 2017

Preprocessor Directive

A pre-processor directory is a set of text which is start with # symbol. When C source code compile then process of compilation get start from pre-processor directory. It means all pre-processor directories compile before actual compilation.

Preprocessor Directive C Language

  • Header files
  • Macro
  • Conditional Compilation statements

why do we need pre-processor directives

We use pre-processor directives for a variety of things:

1. Macro replacement: To replace a particular text pattern with another one. This achieves one of several things - replace a text pattern with a constant or replace a text pattern with a parameterized expression - #define

2. Define a variable that the per processor can see - #define

3. Includes source code from external files - #include

4. Conditionally exclude a block of code from the original source code that will be subsequently processed by the compiler. This is done using previously defined pre processor variables - #ifdef or #ifndef

Various Pre-processor Directive

Substitutes a preprocessor macro.
Inserts a particular header from another file.
Undefines a preprocessor macro.
Returns true if this macro is defined.
Returns true if this macro is not defined.
Tests if a compile time condition is true.
The alternative for #if.
#else and #if in one statement.
Ends preprocessor conditional.
Prints error message on stderr.
Issues special commands to the compiler, using a standardized