Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Compilation Process & Execution of C Program

Compiler converts C programs into executable file. Compiler has four phases to ouptut an executable file. And these are -

  • Pre-processing
  • Compilation
  • Assembly
  • Linking

Pre-processing - This is the first phase through wich C code is passed. This phase has sub phases -
1. Removal of Comments
2. Expansion of Comments
3. Expansion of header file

This phase is handled by "Pre-processor" which is one unit of compiler. When code contains anything which start with "#" (hash) like #include, #define etc.. the proceprocessor is invoked. The preprocessor output is stored in filename.i file. We can see this file by opening filename.i file. This phases increases the size of file becuase the expansion of header file take place in this phase.

Compiling - The next phase is to compile filename.i. In this phase filename.i is compiled into filename.s file. This file contains assembly level instructions. The extension of this file is filename.s

Assembly - In this phase the filename.s file is converted into object code which has .o extension. This file has machine level instructions. In this phase all code is converted into machine language except the library function like printf(), scanf() etc..Since this file contains machine code so we can't see its content.

Linking - Linking is last phase of compilation process. In this phase linking of library functions is done i.e functions definition is inserted into the file and linker knows from where the library function definition should be taken. This phase also increase the size of file as it adds the code from library functions.