[Good programmer notes sharing] -- preprocessing and programmer notes preprocessing
IOS training ------ my C Language notes. I look forward to communicating with you!
In fact, there is such a process in the Process of C language remote travel,
Compile: C ----> executable file (runable)
1:. C ------. I preprocessing (before and after C syntax)
2:. I -------. s compilation (previously C syntax, followed by Assembly syntax)
3:. s ------. o assembly
4:. o ------ executable program Link
Next we will talk about the first step of preprocessing:
I. Introduction to preprocessing
2. Definition of Macros in Preprocessing without macro parameters
# Define M (x + y + 3 + xy) with macro Parameter Definition
# Define M (x, y) (x + xy + 3 + xy) 3: Use main (){
Int Num = M; int Num2 = M (2, 5); printf ("% d, % d", Num, Num2 );
} Here we use the two macros defined above, that is, the use of preprocessing commands.
Iv. Common preprocessing commands
E> predefined macros (undef cannot be canceled)
Some predefined macros are specified in the C standard and are often used in programming. The following table lists some predefined macros that are frequently used.
_ DATE __
Date of preprocessing (string text in the form of "Mmm dd yyyy)
_ FILE __
String text representing the current source code file name
_ LINE __
An integer constant representing the row number in the current source code.
_ TIME __
Source File Compilation Time, in the format of "hh: mm: ss"
_ Func __
Current function name
It is useful for macros such as _ FILE __,__ LINE __,__ func _ in program debugging, because you can easily know the row of the file to which the program runs and the function.
The following example prints the predefined macros.
V. Preprocessing Summary
- 1. the preprocessing function is unique in C language. It is completed by the Preprocessing Program before the source program is officially compiled. The programmer calls these functions using preprocessing commands in the program.
- 2. The macro definition uses an identifier to represent a string, which can be a constant, variable, or expression. In macro calls, this string is used for macro name replacement.
- 3. The macro definition can contain parameters, and the macro is called with real parameters instead of form parameters. Instead of "value transfer ".
- 4. To avoid macro replacement errors, brackets should be added to the macro definition strings, and the formal parameters in the strings should also be added to the brackets.
- 5. file inclusion is an important function of preprocessing. It can be used to connect multiple source files into one for compilation. The result will generate a target file.
- 6. Conditional compilation allows you to compile only program segments that meet the conditions in the source program, so that the generated target program is shorter, thus reducing the memory overhead and improving the program efficiency.
- 7. The pre-processing function is used to facilitate program modification, reading, porting and debugging, as well as modular program design.