Compiler working principle and process

Source: Internet
Author: User

1. Preprocessing
At this time, the compiler will scan the C source files one by one. h file, the entire. the H file is included in. c file to form a new. c file (the actual implementation process may not be like this, but the principle is like this ). At the same time, interpret related pre-processing commands, such as replacing macros with actual values.

2. Compile the source file
At this time, the compiler will scan the source file generated after step 1Source codeCompile the code into a machine code to generate the target file. If you find that a type is not a self-contained type of the compiler, such as some custom struct, you will find this type in the source file.Can I find the declaration of this type?If not, an error is returned.All functions generate only one symbol during compilation and do not check whether the actual body exists.However, if you find thatCodeIf the declaration of this function is not found before the row, the compiler will give a warning: implicit function call.

3. link all target files
In this case, the compiler collects all the symbols in the target file, such as function symbols, andSearch for EntityIf no address is found, an error is returned. If no error is found, a real address is assigned to these symbols. After an address is assigned, the actual address is replaced with the symbol in each target file, merge all target files into an executable file.

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.