Contents of the program environment

        This part is more important, and there is an interview to test this.

Table of contents

Program translation environment and execution environment:

Translation environment:

Compile + link:

Operating environment:


Program translation environment and execution environment:

        In any implementation of International C, there are two different environments. The first is the translation environment, in which the source code is converted into executable machine instructions; the second is the execution environment, which is used to actually execute the code.

Translation environment:

        The source file will be converted into an object file after processing by the compiler, and then enter the linker and link library to form an executable program. Link libraries are other things provided by the compiler. The compiler uses c1.exe in Windows , and the linker uses link.exe . These two programs can be found in everything.

Compile + link:

        There are three parts in compilation (as shown in the figure):

          After compilation, linking is performed: 1. Merging segment tables; 2. Merging and relocating symbol tables.

       To find functions across files in a link.

       Merge the same data in elf format and merge the symbol tables. Each symbol table has a corresponding address. If it is just declared, the stored address cannot be used.

       Using the symbol table to look up functions is based on address search. If the address in the symbol table is wrong, the corresponding function cannot be found, and a link error occurs.

       There are overloading in C++, and renaming is complicated. The parameters are different, and the renaming is also different.

Operating environment:

Program execution process:

1. The program must be loaded into memory , in an environment with an operating system: Generally this is done by the operating system. In an independent environment, the loading of the program must be arranged manually, or it may be placed read-only through executable code. memory to complete.

2. The execution of the program begins, and then the main function is called .

3. Start executing the program code . At this time, the program will use a runtime stack to store the local variables and return address of the function. The program can also use static memory. The variables stored in the static memory are in the program. Their values ​​are retained throughout execution.

4. Terminate the program , terminate the main function normally, or terminate unexpectedly.

Guess you like

Origin blog.csdn.net/2301_77868664/article/details/130906899