|
to process the program source code.
|
/* .....
.....
..... */
|
/* This is a comment in a C program */ |
// This is now allowed as comment |
Demo:
|
# 1 "comment.c" # 1 " |
How to run the program:
|
|
#define <identifier> <replacement token list> #define <identifier>(<parameter list>) <replacement token list> |
Meaning:
|
|
Example:
#define PI 3.141592653589793238462643383279502884197
#define MAX 99999
int main( int argc, char* argv[] )
{
int x;
double y;
x = MAX;
y = PI;
}
|
After processing with gcc -E constant.c:
int main( int argc, char* argv[] )
{
int x;
double y;
x = 99999;
y = 3.141592653589793238462643383279502884197;
}
|
How to run the program:
|
Example:
#define square(x) (x*x)
int main( int argc, char* argv[] )
{
double a, b;
b = square(a);
}
|
After processing with gcc -E macro1.c:
int main( int argc, char* argv[] )
{
double a, b;
b = (a*a); ( square(a) ---> (a*a) )
}
|
How to run the program:
|
|
Example:
#define sum(x,y) x+y /* Sum: x+y */
int main( int argc, char* argv[] )
{
double a, b, c;
c = sum(a, b); /* Compute a+b */
c = 2*sum(a, b); /* Compute 2*(a+b) ??? */
}
|
After processing with gcc -E macro2.c:
int main( int argc, char* argv[] )
{
double a, b, c;
c = a+b;
c = 2*a+b; /* Wrong !!! Not equal to: 2*(a+b) !!! */
}
|
How to run the program:
|
#undef macro-name
|
Example:
#undef PI
#undef MAX
#undef square
|
#include <filename> - include file "filename" from
the C's standard include directory
(which is: /usr/include)
#include "filename" - include file "filename" from
a user specified diretory
|
The default user specified include directory is:
|
gcc -Idir1 -Idir2 .... C-program |
The C compiler will look for include files included with #include "..." in directories dir1, dir2, etc.
|
| file1.h | include1.c |
|---|---|
#define square(x) (x*x) |
#include "file1.h"
int main( int argc, char* argv[] )
{
double a, b;
b = square(a);
}
|
Output of gcc -E include1.c:
int main( int argc, char* argv[] )
{
double a, b;
b = (a*a);
}
|
|