Explanation of C language preprocessing and C language preprocessing

Source: Internet
Author: User

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

Related Article

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.