Wednesday, April 6, 2016

Preprocessor Directives in C++

The C++ preprocessor is a collection of special statements, called directives, that are executed at the begenning of the compilation process.
The preprocessor is usually an integral part of our compiler. It is a process that is executed by the compiler before our C++ program code is compiled into machine instructions. The job of the preprocessor is to prepare our source code, proper for the compile phase, according to the instructions that we have included in the source files. These instructions are called preprocessor directives.
All preprocessor directives begin with the symbol #, so they are easily distinguishable from C++ language statements.
Given below is the complete set of preprocessor directives:
DirectiveFunction
#includeSupports header file inclusions
#if, #else, #elif, #endif, #if defined (or #ifdef), #if !defined (or #ifndef)Enables conditional compilation
#define, #undefEnable symbol and macro substitution
#lineAllows redefinition of current line and filename
#errorProduces compile-time error message
#paragmaOffers machine-specific features while retaining overall C++ compatibility
We have already used preprocessor directives in out past examples,and we are very familiar with the #include directive by now.

0 comments:

Post a Comment