C preprocessor directives
All the preprocessors in c are not part of actual c programming language. When c language had introduced in the market there are different architecture of computers was present. To make the c language portable in different architectures or compilers, c language developer had introduced preprocessor. It is only instruction to compiler. All the preprocessor process before the staring of actual compilation and create an intermediate file. In the intermediate file all preprocessor statement is replaced by corresponding c code. During the compilation process that intermediate file is deleted by compiler automatically.
To see the intermediate file in linux gcc compiler:
Suppose there c source code file test.c
Compile the c code with following options:
It will create three more files in same directory. They are:
1. test.i : Intermediate file
2. test.o : Object file
3. test.a : Assembly file
To see the intermediate file in Turbo c compiler:
Step 1: First create any c file let us assume test.c which contains:
#include<stdio.h>
#define max 10+2
int main() {
int a;
a = max * max;
printf("%d",a);
return 0;
}
Step 2: Go to command prompt. (Open run in window XP. Then write cmd then press enter key.)
Step 3: Go to the directory where test .c has been created.
Step 4: write in the command prompt:
and press enter key (to create intermediate file)
Step 5: type test.i (to see the intermediate file)
We can observe in the intermediate file all the preprocessor statements has been replaced by actual c code. We will discuss more about intermediate file in the later chapters.
Why preprocessor in c programming language?
Answer:
1. It improves the readability of program.
2. It makes easy to modify
3. Portability
Preprocessor definitions in c
Preprocessor directive in c
#include directive in c
# define directive in c
Pragma directive in c
Warning directive
Preprocessor operators in c
# if directive in c
#line directive in c
# error directive in c
# elif in c
# ifdef and #endif in c
# ifndef in c example
#undef in c
What is header file in ?
C preprocessor questions
C tutorial home.
3 comments:
It works 4 me . thank you
I tried but didn't work for me ..
I tried with the option
gcc -save-temps -c test.c
then it worked for me
How many preprocessor directives in C and what they exactly defines?
Post a Comment