|
The first step in dealing with C language compiler after the pretreatment, is to deal with the .c file .i file. When the compiler to do some preprocessing expand the replacement process.
1> header file to start soon #include "stdio.h" file similar expanded.
2> macro definition replacement work, the program is about to replace the contents of the macro definition good.
#include "stdio.h"
#define R 10
int main ()
{
int a = R;
}
After preprocessor code changes
//...stdio.h contents of not showing
// Place the macro definition has been replaced in the program
int main ()
{
int a = 10; return 0;
}
Replace macro to do is replace a whole, and syntax-independent, it does not follow the rules of grammar.
Macro definitions generally used in two ways, one is to define a constant, and the other is to define a macro function.
#define N (n, m) n + m // macro definition
int main ()
{
int c;
c = N (1,2); // sum of 1 and 2 return 0;
}
In fact, after pre-treatment becomes
int main ()
{
int c;
c = 1 + 2; return 0;
}
Another application macro function, because the macro syntax definition does not consider it just as a whole substitution, so you can write without considering the type of function variables, and this is his advantage
For example, the following code:
#define N (n, m) n + m // macro definition
int main ()
{
int e = N (10,20) * N (10,20) // After preprocessing is int e = 10 + 20 * 10 + 20;
// The above error is easy to count! !
return 0;
}
3> Conditional Compilation: Some statements in the hope that when the conditions are met to compile.
#ifdef identifier
// Block 1
#else
// Block 2
#endif
When the identifier has been defined, only 1 block compiled participate
At the same time of its use and define a replacement job is done.
With some knowledge of the C language. . . See the video to learn Linux C language. |
|
|
|