Professional Documents
Culture Documents
ANDHRA PRADESH
Name :M.Subramanyam
Designation :Senior Lecturer
Branch :Computer Engg.
Institute :Q.Q.Govt.Polytechnic,Hyderabad.
Year/Semester :III Semester
Subject :UNIX & C
Subject Code :CM-304
Topic :Preprocessor directives
Duration :50 Min
Sub Topic :Types, Symbolic constants & Macros
Teaching Aids :PPTs, Animations
CM304.87 1
Recap
What is a compiler?
What is a linker?
CM304.87 2
Objectives
CM304.87 3
Preprocessor
Preprocessor is a program.
CM304.87 4
Compiling C Programs
C compiler
Easy to
Develop program
Read programs
Modify programs
Portable
Reuse
CM304.87 7
Types of preprocessor directives
7) #elif
8) #endif
9) #undef
10) #error
11) #line
12) #pragma
CM304.87 9
Types of preprocessor directives
Preprocessor Meaning
Directive(s)
#include Treats text in the file specified by filename as if it
appeared in the current file.
#define Defines a macro/Symbolic constant.
#if , #ifdef, #ifndef, #else, Conditional compilation directives.
CM304.87 10
The #define Preprocessor Directive
1)Symbolic Constants
replacement value.
CM304.87 11
The #define Preprocessor Directive
#define FALSE 0
To undefine a macro
CM304.87 13
The # define preprocessor directive
2)Macros
#define IDENTIFIER(arg1,agr2,….agrn) body
agr1,agr2…agrn are arguments, body is the
body of the macro.
A macro without arguments is treated like a
symbolic constant.
When the macro is called, the call is replaced
by its body.
Well suited for small functions and functions
are called frequently.
CM304.87 14
The # define preprocessor directive
Contd..
Function Macro
Function call is nothing but Macro call is nothing but
branching. substitution.
Program execution is slow. Program execution is fast.
Example body
Name argument
#define CIRCLE_AREA( x ) ( PI * ( x ) * ( x ) )
Calling Macro
area = CIRCLE_AREA( 4 );
to become
area = ( 3.14159 * ( 4 ) * ( 4 ) );
CM304.87 16
Example
CM304.87 17
Nested Macros
CM304.87 18
Example
CM304.87 19
Summary
Defining macros.
CM304.87 20
Quiz
CM304.87 23