C Language Difficulty 2 pre-processor

Source: Internet
Author: User

C Language Difficulty 2 pre-processor 1 preprocessing phase during the preprocessing phase, the C preprocessor does some textual manipulation of the source code before it is compiled.  Its main tasks include deleting comments, inserting the contents of the files that are included in the specified include, defining and replacing the symbols defined by the # define directive to determine whether portions of the code should be compiled according to some conditional compilation instructions. 2 #define命令 the easy-to-err point of using macro definition: Format: #define NAME stuff with this instruction, the preprocessor converts it to stuff whenever the symbol name appears behind this instruction. Note: You cannot add a semicolon after the macro definition, #define机制包括了一个规定, allowing you to replace the parameter with text, which is commonly called a macro or a macro; Format: #define NAME (parameter-list) stuff where Paramet The ER list is a list of UI symbols separated by symbols, and they may be out of the case in stuff. Note: (1) The opening parenthesis of the argument list must be adjacent to name.      If any whitespace exists between the two, the argument list is interpreted as part of the stuff. (2) Pay attention to the use of brackets, due to the different sequence of operations, the addition of parentheses will directly affect the results. Example:

3 #define替换步骤

4 inserting macro parameters into a string two tricks: first, the automatic connection of adjacent strings makes it easy for us to break a string into a few paragraphs, and no paragraph is actually a macro parameter. For example: The second technique uses a preprocessor to convert macro parameters to a string, #argument这种结构被预处理器翻译为 "argument". This example: Note that one of the more peculiar uses of the # #结构 is to concatenate the symbols on either side of it into a symbol. As one of the purposes, it allows macro definitions to create identifiers from detached text fragments. For example:

5 the macro parameter with side effects is that the parameter will be the most initial value each time it is used, and will not change due to the change in processing, as we discussed in the 2nd part above. 6 comparison of macros and functions

7 #undef命令 instruction Format #undef name if an existing name needs to be redefined, its old definition must first be removed with #undef. 8 conditional compilation

The complete syntax:

9 whether it is defined or not, sometimes it is necessary to determine whether a symbol is defined, and any sentence in the following statement can be

The 10 file contains a # include directive: The preprocessor deletes this instruction and replaces it with the contents of the containing file. If a header file is included in 10 source files, it is actually compiled 10 times. Library functions include: #include <filename> local file contains: #include "filename" 11 other instruction Error directives: #error text of the error message this directive allows you to generate error messages #line directive: #line number "string"

12 Summary of Programming hints

C Language Difficulty 2 pre-processor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.