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:
Directive | Function |
---|---|
#include | Supports header file inclusions |
#if, #else, #elif, #endif, #if defined (or #ifdef), #if !defined (or #ifndef) | Enables conditional compilation |
#define, #undef | Enable symbol and macro substitution |
#line | Allows redefinition of current line and filename |
#error | Produces compile-time error message |
#paragma | Offers 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.
It’s very effortless to find out any topic on net as compared
to textbooks, as I found this piece of writing at this web site.