What happens when you type gcc main.c?
When we GCC the file main.c we compile code and happens different actions like:
1. Reading the source file
2. Processing it
3. Linking it with a runtime library
Let´s know more about code when is being processed.
A compiler has multiple modules: preprocessor, compiler, assembler and linker.
When we write the file main.c, the preprocessor generates some intermediate file, that file is ready to the compiler. Next step is that the compiler compiles files generated by the preprocessor as input, and that generates assembly code, so it can convert our C program file into the assembly language. Computers can only generate binary code, which is why assembly language is the format it needs to work with.
Wait a little!, assembler code is still not understood by the machine ( it needs to be converted into machine code ). The converter that makes this job is the assembler. The assembler module will convert the assembly code into the object code.
Finally the linker, the last module, links the object code (created by the assembler) with library functions code that we use (when we write our code). From that linkage .txt files are generated.
Let’s talk about each module:
The preprocessor makes 3 tasks: removing comments from the code, includes the header file (standard in C files) into the generated file itself, and if any macros were used, will replace the macro name with code.
The compiler will take the file (created by the preprocessor) code and create the assembly code. The assembly code are comprised of mnemonic instructions defined by english words.
The assembler converts the assemble code into the object code.
Finally, the linker can play one of two roles:
1. Can merge multiple C files by compiling them, into one executable file.
2. Links our code (generated from the binary code of the assembler output) with the library function code.
The linker will pack all the code into a single file, which is known as the .exe file (executable file).
Proudly written by Imanol Asolo (Codecodix), September 30 2021.
Comentarios
Publicar un comentario