Download presentation
Presentation is loading. Please wait.
1
Chapter 11: The Preprocessor
2
Introduction Is a program that processes the source code before it passes through the compiler. AKA preprocessor command line or pre-processor directives Are placed in the source program before main line All begin with # Example: #include, #define, #typedef ….
3
Set of commonly used preprocessor
#include: specifies the files to be included #define: defines macro substitution #undef: Undefines a macro #ifdef : Test for maco definition #endif: Specifies the end of #if #ifndef: Test whether a macro not defined #if: Test a complete time condition #else: Specifies alternative when #if test fails
4
Types Macro substitution directives File inclusion directives
Compiler control directives
5
Macro Substitution The key word #define followed by identifier and string Eg: #define FALSE 0 # define PI 3.14 # define CAPITAL “KATHMANDU” Types: SIMPLE ARGUMENTED NESTED
6
SIMPLE Previous slide example are all simple No argumented Eg: 1
7
Macros with arguments Pass argument with macro Eg 2:
Some commonly used are #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define ABS(a,b) (((a)>0)?(a):(-(a))
8
Nesting of Macro #define SQUARE(X) ((X)*(X))
#define CUBE(X) (SQUARE(X)*(X))
9
File Inclusion We have already used it to include file
Eg: #include <stdio.h> #include ”TEST.c”
10
Compiler control Directive
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.