: Preprocessor directives like #define come into effect as soon as they are seen and remain in effect until the end of the file that contains them; the program's block structure is irrelevant.

Preprocessor directives like #define come into effect as soon as they are seen and remain in effect until the end of the file that contains them; the program's block structure is irrelevant.

• Preprocessor directives like #define come into effect as soon as they are seen and remain in effect until the end of the file that contains them; the program's block structure is irrelevant. • Preprocessor mainly performs these tasks on the HLL code: . Removing comments: removes all the comments. A comment is written only for the humans to understand the code and hence are of no use to a machine. So, preprocessor removes them as they are not required in the execution and won't be executed as well. • File inclusion: Including all the files from library that our program needs. In HLL we write #include which is a directive for the preprocessor that tells it to include the contents of the library file specified. For example, #include will tell the preprocessor to include all the contents in the library file stdio.h This can also be written using double quotes-#include "stdio.h". If the filename is enclosed within angle brackets, the file is searched for in the standard compiler include paths. If the filename is enclosed within double quotes, the search path is expanded to include the current source directory. Macro expansion: Macros can be called as small functions that are not as overhead to process. If we have to write a function that needs to be called again and again, then we should prefer a macro over a function. Defining these macros is done by preprocessor. . Preprocessor directives: #define Substitutes a preprocessor macro. #include Inserts a particular header from another file. #undef Undefines a preprocessor macro. #ifdef Returns true if this macro is defined. #ifndef Returns true if this macro is not defined. #if Tests if a compile time condition is true. #else The alternative for #if. #endif Ends preprocessor conditional. #error Prints error message on stderr. #pragma Issues special commands to the compiler, using a standardized method. #elif #else and #if in one statement. The C preprocessor is a macro processor that is used automatically by the C compiler to transform our program before actual compilation. It is called a macro processor because it allows you to define acros, which are brief abbreviations for longer constructs. The C preprocessor provides four separate facilities that you can use as you see fit: • Inclusion of header files. These are files of declarations that can be substituted into your program • Macro expansion. You can define macros, which are abbreviations for arbitrary fragments of C code, and then the C preprocessor will replace the macros with their definitions throughout the program. Conditional compilation. Using special preprocessing directives, you can include or exclud parts of the program according to various conditions. • Line control. If you use a program to combine or rearrange source files into an intermediate fil which is then compiled, you can use line control to inform the compiler of where each source lin originally came from.

Post a Comment

0 Comments