In the previous article we’ve study about C PREPROCESSOR AND ITS TYPES. In this section we’ll study further more about TYPES OF C LANGUAGE PREPROCESSORS. As we know ,preprocessor is a program that processes our source program. Before it is pass to compiler. The preprocessor offer several features. These called preprocessor directives. Each of the them starts with # symbol. These can be place anywhere in program. Further ,In this section we will study about file inclusion and conditional compilation that are TYPES OF C LANGUAGE PREPROCESSORS.
TYPES OF PREPROCESSORS:
FILE INCLUSION :
This directive causes one file to be include in another. Also The command for file inclusion looks like this: #include “filename”. And it simply causes the entire contents of the filename that the file being include exists. There exists two ways to write #include statement.
- #include “filename” : this command will look for the file in the current directory as well as in specified list of directories.
- #inlude<filename> : this command simply look for the file in the specified list of directory only.
CONDITIONAL COMPILATION:
We can, if we want, have the compiler to skip over a part of source code. By inserting the preprocessor commands. #ifdef and #endif , which have general form as:
#ifdef macro name statement1; statement2; statement3; #endif
If macro name is define , the block code will be process as usual. Otherwise not.
USES OF #ifdef:
To comment out some lines of codes. We might have already written some comments in a code that we are about to comment out. This means we end up with nested comments. Obviously. This solution won’t work. Since we can’t nest comments in C language. Therefore, the solution is to use conditional compilation.
#if and #elif directives:
The #if directive can be use to test a condition. Whether it evaluates to a non- zero value or not. If result is non zero then subsequent lines up to a #else #elif and #endif are compiled otherwise not. They’ll be skipped.