preprocessor in c

6
INTRODUCTION TO C PREPROCESSOR

Upload: prabhu-govind

Post on 13-Dec-2014

46 views

Category:

Education


0 download

DESCRIPTION

Preprocessor in C S-Teacher

TRANSCRIPT

Page 1: Preprocessor in C

INTRODUCTION TO C PREPROCESSOR

Page 2: Preprocessor in C

C Preprocessor

OverviewPreprocessor DirectivesConditional Compilation

Page 3: Preprocessor in C

Overview

Six phases to execute C:1. Edit2. Preprocess3. Compile4. Link5. Load6. Execute

Page 4: Preprocessor in C

C Preprocessor

All preprocessor directives begin with #Possible actions

Inclusion of other filesDefinition of symbolic constants & macrosConditional compilation of program codeConditional compilation of preprocessor

directives

Page 5: Preprocessor in C

Preprocessor Directives

#define for symbolic constants#define identifier text

Creates symbolic constants The “identifier” is replaced by “text” in the

programExample

#define PI 3.14

area = PI * radius * radius; Replaced by “area = 3.14 * radius * radius” by

preprocessor before compilation

Page 6: Preprocessor in C

Conditional Compilation Controls the execution of preprocessor

directives & compilation of codeDefine NULL, if it hasn’t been defined yet#if !defined(NULL)#define NULL 0

#endifUse to comment out code (for comments)#if 0code prevented from compiling

#endif