The preprocessing command in C is set by the ANSIC, but it is not part of the C language, which cannot be compiled directly because the compiler cannot recognize them. The procedure must be "pretreated" before the program, including lexical and syntax, code generation, optimization, etc.), etc., for example: if the #include command is included in the program "stdio .h ", when pre-processed, replace the actual content in the stdio.h file instead of the command. The pre-processed programs are as clean as if the pre-processed program is not used, and then compile it by the compiler to get the target code for executable. The current compilation system includes pretreatment, compilation, and connection portions, which are compiled. What we have to remember is that the preprocessing command is not part of the C language, which is done by the pre-processing program before the program is compiled. The preprocessing function provided by c mains with main: macro definitions, files, and conditional compilation. Their orders are starting with "#". First, macro definition: use a specified identifier to represent a string, its general form is: #define identifier string #define pi 3.1415926 We call the identifier "macro name", in the pre-transdermal macro The process replaced with a string is called "macro", and #define is a macro definition command. Several questions should be paid to: The error is displayed only if it is formally compiled. 2, macro definition is not a C statement, do not have to be divided in line, if the semicolon is added, it will be replaced together. 3, the #define statement appears outside of the function in the program, the macro name is valid for the definition command to the end of the source file, usually the #define command writes the beginning of the file, before, as part of the file, valid within this file . 4. You can terminate the scope of the macro defined by the #undef command. Such as: #define pi 3.1415926 main () {
} #} The pi in mysub does not represent 3.1415926 in MySub. 5. When macro definition, you can reference a defined macro name, you can replace it. 6. The characters in the string in the program are in the program, even if they are the same as the macro name, they are not replaced. 7, macro definition is a proprietary noun specifically used for the pretreatment command, which is different from the meaning of the definition variable, only the character replacement does not do memory allocation.
Macro definition with parameters, not only simple string replacement, also perform parameter replacement. The general form of definition is: #define macro (parameter table) string, such as: #define s (a, b) a * b, is int area; area = (2, 3); belt parameters Macro definition is to expand this: if there is a macro with parameters (such as Area = (2, 3)) in the program, press the string specified in the #define command line from left to right. If the strings are included in the macro (such as A, B), the associated parameters in the program statement (can be constant, variables, or expressions) are replaced. If the characters in the string in the macro definition are not a parameter character (as above *), the retained string is formed. The macro with parameters has many similarities. When the call function is called in the braces after the function name, the number of participation is also required to participate, but there is still a big difference between them, mainly : 1, when the function is called, first seek the value of the real parameter expression, and then into the form, and the macro with the parametric is just a simple character alternative. 2. The function call is to assign a temporary memory unit for the process of processing when the program is running. The macro show is carried out before compiling, and does not assign memory units when expanding, and does not have the value of the value. 3. The type of parameters in the function must be defined, the type requirements of the two are consistent, if inconsistent, the type conversion should be performed; and the macro does not have type problems, macro nameless, its parameters have no type, Just a symbol representative, expand the specified string into the specified string. When macro is defined, the string can be any type of data. 4. The function call can only get one return value, and the macro can be tried to get a few results. 5. Use a number of macros more, the macro shows the post-source length, because it does not expand it, and the function call will not be like this. 6, macro replacement does not occupy the runtime, only accounting time, and the function call takes up the runtime (allocation unit, keep the field, value delivery, return).
Second, the file contains: One source file can contain all the contents of another source file into in, and additional files are included in this document. #include