In this section, I am writing few details about the execution flow of a “C” Program.
The following is the execution process of a “C” Program in high level.
In other words, “sample.c” is the input file and “sample.exe” or “a.exe” is the output file of the “C” program.
Figure : High Level View
1) C program (source code) is sent to preprocessor first. The preprocessor is responsible to convert preprocessor directives into their respective values. The preprocessor generates an expanded source code.
2) Expanded source code is sent to compiler which compiles the code and converts it into assembly code.
3) The assembly code is sent to assembler which assembles the code and converts it into object code. Now a sample.obj file is generated.
4) The object code is sent to linker which links it to the library such as header files. Then it is converted into executable code. A sample.exe file is generated.
5) The executable code is sent to loader which loads it into memory and then it is executed. After execution, output is sent to console.
Now directly, jump in to the concept to look over the intermediate files in this process.
We can see all the intermediate file generated, with the help of the following commands. Create a “C” Program file with filename in a current working directory and execute the following commands from the command prompt to see the intermediate files of ‘c’ program.
|E:\Education\C\Programs>gcc -E sample.c -o filename.i
E:\Education\C\Programs>gcc -S filename.i
E:\Education\C\Programs>gcc -c filename.s
To get all the files in a single shot, you can use the following command. after executing this command from the command prompt go and check the files in the current working directory.
|E:\Education\C\Programs>gcc -save-temps sample.c -o filename|