What operations are performed by the program during the compilation, linking, and runtime?

Source: Internet
Author: User

 

The source file compilation process includes two main parts: And the conversion between them is automatic.Let's talk about the steps to implement a program function.
Step 1: Enter your original program (F. C) in the editing window (in advanced language)
Step 2: compile your original program into a binary-form target code (f. o) that can be recognized by the computer)
Step 3: connect the above target code input memory with the library functions provided by the system and other target code to the executable EXE file f.exe.
Step 4: transfer the executable EXE file to the memory for running.   The first stage is the preprocessing stage,Before the official compilation phase. In the preprocessing phase, the content of the source file will be modified according to the pre-processing commands that have been placed in the file. # The include command is a preprocessing command that adds the content of the header file to the. cpp file. There are many other preprocessing commands.
This method of modifying source files before compilation provides great flexibility to adapt to the constraints of different computer and operating system environments. The Code required by one environment may be different from the Code required by another environment, because the available hardware or operating system is different. In many cases, you can place the code for different environments in the same file, and then modify the code in the preprocessing phase to adapt it to the current environment. The Preprocessor is displayed as an independent operation, but generally cannot be executed independently of the compiler. When the compiler is called, the preprocessing process is automatically executed before the code is compiled. The compiler outputs machine code for a given source file. It takes a long time to execute this process. No connection is established between object files. The object file corresponding to a source file contains function references defined in other source files or references of other specified items. These functions or items are still not parsed. Similarly, there is no connection to the same library function. In fact, the code of these functions is not part of the file. These tasks are done by the link Program (sometimes called the link editor. The compilation method refers to the use of a previously compiled machine language program called the Compilation Program, which is stored in the computer as system software. After the user inputs the source program compiled in the advanced language into the computer, compile the program to translate the source program into a machine language equivalent to the target program, and then the computer executes the target program to complete the operations to be processed by the source program and obtain the results. The second is the link program stage.Combine Machine codes in all object files and parse cross references between them. It also integrates the code of library functions used by the object module. This is a simplified representation of the linking program, because it is assumed that all links between modules are static in the executable module. In fact, some links are dynamic, that is, these links are established during program execution.
The link program statically establishes the link between functions, that is, the function link included in the source file of the component program is established before the program is executed. Links between dynamically created functions (links established during program execution) Compile and link the functions to create another executable module-dynamic link library or shared library. The function link in the dynamic link library is established only when the program calls the function. Before the program calls the function, the link does not exist.
The Dynamic Link Library has several important advantages. One major advantage is that functions in the dynamic link library can be shared among several parallel programs, which saves the memory space occupied by the same function. Another advantage is that the dynamic link library will not be loaded into the memory before calling the function. That is to say, if the function in the given dynamic link library is not used, the dynamic link library will not occupy the memory space. The following are some examples:  
Currently, Java is compiled at runtime. The compilation method is different from that of C ++. All objects are dynamically allocated memory. The advantage of Java is that you do not need to delete the objects. The virtual machine is responsible for memory revocation.

Memory Management in C ++ is divided into three types:
(1) distribution from the static storage area. The program has been allocated when it is compiled, and the program exists throughout the entire runtime. For example, global variables and static variables.

(2) create a stack. When a function is executed, the storage units of local variables in the function can be created on the stack. When the function is executed, these storage units are automatically released. Stack memory allocation computation is built into the processor's instruction set, which is highly efficient, but the memory capacity allocated is limited.

(3) allocate from the stack, also known as dynamic memory allocation. Program inRunningWhen using malloc or new to apply for any amount of memory, the programmer is responsible for when to use free or delete to release the memory. The lifetime of the dynamic memory is determined by us. It is very flexible to use, but it has the most problems.

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.