Precession command in C

xiaoxiao2021-03-06  48

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 or #include "file name" feels like a package in Java, and its role is like in J2EE we can use * .xml to make a configuration file, then call this file, but if this file is After the modification, all files that use (include) this file (because it is copied for use), it needs to be compiled from the new, it seems to have lost flexible meaning. In the #include command, the file name can be enclosed in "" or <>, and their difference is <>, the system is used to store the file to be included in the user's current directory. If you can't find it, follow the standard way Find (ie, look up in a plurality of brackets). Generally speaking, if you use a #include command with the #include command to save the relevant header file with the #include command, save the lookup time. If you want to include a file you have written by the user (this file is generally in the current directory), it is generally "", if the file is not in the current directory, "" can give the file path. Third, if the condition is compiled, all rows in the source program participate in compilation. However, sometimes it is desirable to compile some of the contents only in order to meet certain conditions, that is, designated compilation of content, which is conditional compilation. 1, # indef identifier Procedure 1 #Else block 2 #ENDIF When the specified identifier has been defined by the #include command, only the program is compiled in the program compilation phase, otherwise the program segment 2. 2, # if expression block 1 #Else program segment 2 #ENDIF Advantages: Conditional compilation, can reduce the compiled statement, reduce the length of the target program, reduce the runtime, the target program length It can be greatly reduced.

转载请注明原文地址:https://www.9cbs.com/read-117735.html

New Post(0)