Preprocessor in C

PrabhuGovind 2,959 views 7 slides Apr 30, 2014
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Preprocessor in C S-Teacher


Slide Content

INTRODUCTION TO C
PREPROCESSOR

C Preprocessor
Overview
Preprocessor Directives
Conditional Compilation

Overview
Six phases to execute C:
1.Edit
2.Preprocess
3.Compile
4.Link
5.Load
6.Execute

C Preprocessor
All preprocessor directives begin with #
Possible actions
Inclusion of other files
Definition of symbolic constants & macros
Conditional compilation of program code
Conditional compilation of preprocessor directives

Preprocessor Directives
#define for symbolic constants
#define identifier text
Creates symbolic constants
The “identifier” is replaced by “text” in the program
Example
#define PI 3.14
area = PI * radius * radius;
Replaced by “area = 3.14 * radius * radius” by
preprocessor before compilation

Conditional Compilation
Controls the execution of preprocessor directives
& compilation of code
Define NULL, if it hasn’t been defined yet
#if !defined(NULL)
#define NULL 0
#endif
Use to comment out code (for comments)
#if 0
code prevented from compiling
#endif

Conditional Compilation
Controls the execution of preprocessor directives
& compilation of code
Define NULL, if it hasn’t been defined yet
#if !defined(NULL)
#define NULL 0
#endif
Use to comment out code (for comments)
#if 0
code prevented from compiling
#endif