The preprocessors are the directives, which give instruction to the compiler to preprocess the information before actual compilation starts.
All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not C++ statements, so they do not end in a semicolon (;). We already know #include directive.
Different preprocessor directives (commands) perform different tasks. We can categorize the Preprocessor Directives as follows:
– Inclusion Directives- Macro Definition Directives- Conditional Compilation DirectivesInclusion Directive
This category has only one directive, which is called #include. This inclusion directive is used to include files into the current file. The inclusion directive can be used as follows:
includes stdio.h from include folder
includes cpp class library header iostream
includes my.cpp file from include folder
includes my.h file from current working folder
Macro Definition Directives
These are used to define macros, which are one, or more program statements (like functions) and they are expanded inline.
There are two directives for Macro Definition:
#define – Used to define a macro
#undef – Used to undefine a macro (The macro cannot be used after it is undefined.)
Conditional Compilation Directives
Conditional Compilation Directives these are used to execute statements conditionally for:
– Executing the code on different machine architectures.
– Debugging purposes.
– Macros can be dependent on other macros (must be defined before they are used.)
– Evaluating codes, which are to be executed depending upon the requirements of the programmer.
The following directives are included in this category:
Note: These macros are evaluated on compile time. Therefore they can only use the predefined macros or literals. Most compilers do not support the use of variables with these directives.