Compilation Procedure of C Programs
C language is the compiled programming language that provides source code written by using the editor of the programmer’s choice in the form of the text file.
This text file is compiled into the machine code as per the requirement. The source files are conventionally named with the .c extension in C programming language.
Figure: Compilation procedure in C language.
We can use the gcc command to compile the source code file in the C language. The compiler takes the fresh program’s code and transforms it into the machine language, which can be understood by the computer system.
Compiler Vs. Interpreter
The compiler is the computer program used to translate the computer code from one programming language to another. It can read the source code and outputs the executable code of the particular program.
The interpreter can convert the source code line-by-line during the run time and completely translate it from high-level language to machine level language.
Figure: Difference between the compiler and interpreter.
The interpreter also permits evaluation and alteration of the particular program at the execution time. The program execution of the interpreter is slow as compared to the compiler.
There are four stages of the compilation process in the C programming language, which are as follows:
The pre-processing is the first step of the compilation procedure. Its command begins with #, which is known as pre-processor directives. The commands of pre-processor are used by the given command:
- Removing comments in the program
- Expanding the macros in particular code
- Expand the including files in the library
Compiling stage of the particular program
The compilation of a particular program is the second stage, which takes the pre-processor’s output and produces assembly language. The assembly language is the intermediate human-readable language that is definite to the particular process’s target processor.
Use of assembler in the program
The program can use the assembler after the compilation process, which is the third stage of a particular code. Assemblers can convert the assembly code into binary code or machine code in zeros and ones. The machine code is also known as the object code.
Linking stage of the program
The linking process is the final stage of the compilation process of the particular program. The linker can merge all the object codes from multiple modules within a single module. When we are using the function from libraries, then the linker will link the code with that particular library function code.
When we included the header file like #include