Explanation of C language preprocessing and C language preprocessing
Steps from the. c file to the executable program:
Preprocessing, compilation, assembly, and link
Compiled command:
Preprocessing gcc-E hello. c-o hello. I
Compile gcc-S hello. I-o hello. s
Compile gcc-C hello. s-o hello. o
Link to gcc hello. o-o hello.exe
Pre-compiled commands (4 types ):
File Inclusion: # include
Macro definition: # define
Conditional compilation: # if... # endif
Predefined macros with Special Functions
First, preprocessing has the following functions:
1. copy the files contained in the source file in the "include" format to the compiled source file.
2. Replace the string defined by "# define" with the actual value.
3. Determine the concept of code preprocessing to be compiled based on the conditions following "# if ".
Macro usage:
1. macro is defined as a macro name to represent a string. During macro expansion, the macro name is replaced by this string. This is just a simple replacement. A string can contain any character, either a constant or an expression. The Preprocessing Program does not check it. If any error occurs, it can only be found when the source program that has been expanded by a macro is compiled.
2. The macro definition must be written outside the function, and its scope is macro definition commands that end with the source program.
3. If the macro name can only be enclosed in quotation marks in the source program, the Preprocessing Program will not replace it with macros.
4. macro definitions allow nesting. You can use the defined macro names in macro-defined strings. During macro expansion, the Preprocessing Program is replaced by another one.
5. You can use uppercase letters to indicate the macro name. However, lower-case letters are also allowed.
# Considerations when including header files:
Include system header file: # include <>
Include the custom header file # include ""
# Include can also contain. c files, but is generally not used in this way