PREPROCESSOR DEFINITION OF PREPROCESSOR The C preprocessor or

  • Slides: 8
Download presentation
PREPROCESSOR

PREPROCESSOR

“DEFINITION OF PREPROCESSOR” The C preprocessor or cpp is the macro preprocessor for the

“DEFINITION OF PREPROCESSOR” The C preprocessor or cpp is the macro preprocessor for the C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.

“PREPROCESSOR” Ø The “C” preprocessor is a collection of special statement that are accepted

“PREPROCESSOR” Ø The “C” preprocessor is a collection of special statement that are accepted at the begging of the process. Ø All the preprocessor statement must beginning with “#” character. Ø #Include : The preprocessor is a rather strange feature of C. It is a non interactive editor, which has been placed on the “front” of the compiler. This handles the “#include” directives by physically inserting the named file into what the compiler will eventually see. Ø #define: As the preprocessor is an editor, it can perform search and replace. To put it in this mode the #define command is used. The syntax is simply : #define search _ text replace _ text

Hand written program Executable code (PR 1. EXE) Object code (PR 1. OBJ) C

Hand written program Executable code (PR 1. EXE) Object code (PR 1. OBJ) C Source code (PR 1. C) Expanded source code (PR 1. OBJ)

HOW IT WORKS ? We have used the preprocessor since the very fist program

HOW IT WORKS ? We have used the preprocessor since the very fist program , but never looked in detail at what it can do. The preprocessor is little more than an editor placed “in front of” the compiler. Preprocesso r . c file Compiler Intermediate (Sometimes “. i”) file

INPUT OUTPUT Processor Input Output Editor Program typed from keyboard. C source code containing

INPUT OUTPUT Processor Input Output Editor Program typed from keyboard. C source code containing program and preprocessor commands. Preprocessor C source code file. Source code file with the preprocessing commands properly sorted out. Compiler Source code file with preprocessing commands sorted out. Relocatable object code. Linker Relocatable object code Executable code in and the standard C machine language. library functions.

CHARACTER This character is q #include q #define q #undef q #ifdef q #endif

CHARACTER This character is q #include q #define q #undef q #ifdef q #endif q #if expression q #else q #include “filename” q #include <filename> followed by one preprocessor of the following

STRUCTURE OF PREPROCESSOR #include<stdio. h> #include<conio. h> #define P printf #define S scanf #define

STRUCTURE OF PREPROCESSOR #include<stdio. h> #include<conio. h> #define P printf #define S scanf #define pi 3. 14 int main() { float r; clrscr(); P(“Enter the Perimeter of Circle”); S(“%f”, &r); P(“Perimeter of Circle %f”, 2*pi*r); getch(); return 8; }