17-05-2014, 12:29 PM
C++ Preprocessor Directives
C++ Preprocessor.docx (Size: 48.67 KB / Downloads: 10)
Preprocessor directives:
These are the commands given to a program known as
preprocessor that processes the source code before it passes through the compiler.
Each of these preprocessor directives begins with a # symbol. These can be placed anywhere in the program but usually placed before main ( ) or at the beginning of the program. Before the source code passes through the compiler, it is examined by the preprocessor for any directives. If there are any, appropriate action is taken and the source program is handed over to compiler.
Macro Definition Directives
These are used to define macros, which are one, or more program statements (like functions) and they are expanded inline. (Expanded inline means they are substituted at the place of macro call unlike functions in which the execution pointer moves to the function definition.).
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.)
The above example illustrates the following:
We do not terminate the macros using (
Macros can be parameterized
Macros can be dependent on other macros (must be defined before they are used.)