<< Prev Next >>
Compiling process
Before heading into C syntax and programming, it's interesting to know how a C program is compiled. There are several programs involved on the process, so knowing them, knowing what they do and how to whole process fits together is very important to anyone interested in programming.
First thing to keep in mind is that the computer only understands a sequence of zeroes and ones called machine code. So a computer never understands C, Java or even assembly. All programming languagues need translation to machine code. For C, this is done using the C compiler suite.
1. Preprocessing
The preprocessor is a tool that formats the C code for the compiler. It processes the preprocessor directives, like #include or #define. Each of these directives tells the preprocessor to do something related to replacing, deleting or including chunks of C code. This involves no compiling C yet.
2. Compiling
Once the preprocessor has finished preparing the source code, the compiler transforms the C code into assembly. The compiler applies several optimizations to the code to reduce memory consumption and enhance speed. Thus the compiler generates .s files with the assembly.
3. Assembling
Once the compiler has translated all the C code into assembly, the assembler takes the assembly code and assembles it into what is called object code (.o files). This is effective machine code that the machine can understand, but it still needs external symbols (e.g. printf) to be resolved, and has no executable structure.
4. Linking
Once the object code is generated by the assembler, the linker resolves all external symbols linking the libraries (external code) needed.
5. Executable format
Once linking has been finished, the machine code is structured according to the target executable. This process and tool used differs for each OS, but most common executable formats are Microsoft's Win32 EXE and the Executable and Linkable Format (ELF) (used by most POSIX systems and also all PlayStation consoles). After this step is finished the program is ready to execute on the target architecture.
<< Prev Next >>








