C compiler and environment

"  We usually say the program means the program can be run directly after double-clicking, this program is called executable program (Executable Program), that is, the windows platform common .exe. Your paper to talk about Code written to generate .exe, experience and knowledge of what the period. "

 

 

    Internal executable is a collection of computer instructions and data, which are in binary form, the CPU can recognize; however, the person who writes the code, they are very vague and difficult to remember.

    In fact in the early stages of computer development, it is to use binary instruction to write a program, that's not a programming language.

    Imagine, programmers use a long list of 01 symbols to write programs, is not feeling very collapse.

    Binary instructions programmed directly using simply a nightmare for people, especially when large program, not only to write cumbersome, requiring frequent query instruction manual, but once wrong, face full of 0 and 1, will be extremely upset, confused.

    Therefore, this forcing programmers developed a programming language, increased productivity. For example, the assembler, C language, C ++, Java, Python, etc., are gradually improving development efficiency. So far, the program is no longer only a handful of people can do things, ordinary people go through a learning can also write a decent program.

    C language code by a fixed vocabulary organized according to a certain format it simple and intuitive, easy to identify and understand the programmer, but for the CPU, just as the bible C language, did not know. CPU only know some binary form of instruction. Then you need a tool to convert C code into a binary instruction of the CPU can be recognized, i.e. processed into a code form .exe program, this tool is a special software, which we call the compiler (Compiler) . And before you know compiler, we have to look at the environment.

 

surroundings

    In either implementation in ANSI C, there are two different environments . The first one is the build environment (development environment), in this environment, the source code is converted into executable machine instructions. The second is the runtime environment (Execution Environment), which is used to actually run the code. Standard clearly stated, both settings need not be located on the same machine. For example, the development of multi-platform often involves a word, cross-compiler (cross compiler), which is running on a machine, and it generates executable code can be run on different types of machines. Hardware platform is the case, the operating system as well. In fact, in the development of embedded systems, always encounter this situation, you write code on the pc, and then generate the corresponding executable program through a variety of chip cross compiler on the pc, to transfer the program to the chip up operation.

 

Compile & Link

    The compiler recognizes the code words, sentences, and various specific format, and converts them into a binary form of a computer can be identified, a process known as compilation.

1. Compile

    Compilation process itself also consist of several stages, each consisting of a program source file, respectively, are each converted into a corresponding process by compiling object code (Object code) .

1.1 Pretreatment

    First, preprocessor (Preprocessor) pretreated. This stage, the preprocessor performs some operations in the source code text. For example, instead of the symbol defined by #define command value and the actual content read by the instructions contained #include files.

1.2 compiler

    Then, after the code replacement processor will enter into the pre- compiler (Compiler) . This stage, the parsed source code, according to the rules determining the meaning of each sentence. This stage is where we usually write the code when the vast majority of errors and warnings generated. It is a complex process that involves a variety of complex algorithms and hardware architectures period. If you are computer-related majors, this knowledge can be learned in the "compiler theory" in which to professional courses, roughly divided into the following steps, not to proceed to explain here.

Parsing: Analysis of expression whether to follow the rules of grammar

Lexical analysis: keywords, identifiers, immediate legality

Semantic Analysis: Further analysis of the legality of expression on the basis of analyzing grammar

    After the analysis is complete, the configuration of a code optimization generate the corresponding assembly code file.

    In fact, I do not understand the learning compiler theory does not affect the programming language, not recommended for beginners to delve compiler theory.

1.3 Compilation

    Next, the code proceeds to the assembler (Assembler) , converted it compiled code into machine-executable instructions. In general, compiled object code is generated.

2. Links

    After compiling C code later, it does not generate the final executable file, but generates intermediate files (temporary files) object files.

    And then the linker (linker) object code bundled with links to these files before the final executable file. Format object files and executable file is actually the same, but why do we need to link it to become an executable file? Because the compiler will just write our own code into a binary form, while its operating needs and system components together, these components are necessary to run the program.

    Depending on the mode of the link, the link process can be divided into:

Statically linked , directly into the target executable file

Dynamic Link , after the program starts dynamically loaded object file

    Now if you are a beginner C language, it may not be related to this knowledge, but with in-depth study of the code increases, or even related to the project, it is unlikely to have only one source file. The project ultimately generate a large amount of a source file object file, the linker will need to combine your multiple source object file.

 

 

 

 

 

to sum up

 

 

No matter how simple your code must go through the process in order to generate an executable file compiled links.

The binary code is compiled source code written in "translated" into a machine that can be recognized, they are in the form of the target file. It is compiled for a single source file.

Links are a "package" of course, it will all object files and system components are combined into a single executable file.

In general, what we call "Compiler" actually contains a preprocessor, compiler, assembler, linker, this point does not have to delve too deeply.

Published 60 original articles · won praise 18 · views 20000 +

Guess you like

Origin blog.csdn.net/BadAyase/article/details/102458582