-->

Preprocessor


PREPROCESSOR

What is preprocessor?
·      The preprocessor is a program that processes the source code before passing through a compiler.
·      It operators under the control preprocessor command lines or directives.
·      Preprocessor directives are placed in the source program before the main function.

Categories of the preprocessor directive
The preprocessor directive can be divided into three categories.
a.    Macro substitution
b.   File inclusion directive
c.    Compile control directive

Macro substitution
Macro substitution is a process where an identifier in a program is replaced by a predefined string consisting of one or more tokens.
The preprocessor complete this task under the direction of #define statement.
The macro definition takes the following form.
#define identifier string
The different forms of macro substitution are,
a.    Simple macro substitution
b.   Argument macro substitution
c.    Nested macro substitution

Ø         Simple macro substitution:
·     We have written all macros in capital.
·      String replacement is commonly used define keyword.
·     It is a convention to write all macros in capitals to identify them as symbolic constant.
#define M 5
#define COUNT 100

Ø         Argument macro substitution:
·      The preprocessor give the permission us to define more complex and useful form of replacements.
·      #define identifier (f1,f2……..fn)
·      The identifier f1,f2…… fn are the formal macro arguments that are analogous to the formal in a function definition.

Ø Nesting of substitution
·      If we use one macro in the definition of another macro then it is           called nesting of substitution.
·      Macro definitions may be nested.
·      (SQUARE(X)*(X))*(SQUARE (X)*(X)))

Ø File inclusion directive
·      An external file may containing functions or macro definition as a part of a program so that there is no need to rewrite those functions or macro definitions. This is achieved by the preprocessor directive.
                      #include “filename”
·      The preprocessor insert the entire contents of filename into the source code of the program.When a filename is included in double quotes, the search for the file takes place in the current
directory and then in the standard directories.
·      Alternatively this directive can take the form
#include<filename>
·      In the case of the file without double quotes can only be search
in standard directories.
·      Nesting of included file is allowed. That is, an included other files. However, a file cannot include itself.