×

Compilation Process in C language

What is the Compilation Process?

 The compilation is a method whereby the source code is converted into object code. It is achieved with compiler assistance. The compiler tests the source code for syntactic or structural errors and produces the object code if the source code is error-free.

In object code or machine code, the compilation method c converts the source code that has been taken as an input. The method of compiling can be divided into four stages, i.e., pre-processing, compilation, assembly, and linking.

A pre-processor selects the raw data as an input and extracts all the statements from the code. The pre-processor takes in and interprets the pre-processor instruction. For example, if the directive is accessible in the program <stdio.h>, then the pre-processor interprets the directive and replaces it with the content of the file 'stdio.h.'

Following are the steps that a program goes through until it is translated into an executable form:

  • Preprocessor
  • Compiler
  • Assembler
  • Linker
Compilation Process in C language

Preprocessor

Source code is the code written in a text editor, and an extension is provided to the source code file ".c ». This source code is first transferred to the preprocessor, and then that code is extended by the preprocessor. The extended code is transferred to the compiler after the extension of the code.

Compiler

The code expanded by the preprocessor is passed to the compiler. The code is translated to assembly code by the compiler. Or we can say that the C compiler transforms the preprocessed code into assembler.

Assembler

With the help of an assembler, the assembly code is translated to object code. The name of the assembler generated object file is similar to that of the source file. The object file extension in DOS is ‘obj’, and the filename is 'o' in Unix. If the source file name is sample.c, the object file name would be 'sample.obj.'

Linker

All C-written programs primarily use library functions. These library functions are pre-compiled, and the library files object code is stored with the .lib or .a extension. The linker's main function is to fuse the object code from library files with the object code of our program. Often the situation occurs when the functions specified in other files are referred to by our program; then linker plays a very important role here. It connects those files' object code to our software.

So we infer that the linker's role is to link our program's object code to the library files' object code and other programs. The linker's output is the executable script. The executable file name is similar to the source file, which varies only in its extensions. In DOS, the executable file extension is '.exe', and in UNIX, the executable file can be renamed 'a.out.' For example, if we use the function printf) (in a program, the linker will add its associated code to an output file.

We try to explain you with the help of an example.

#include <stdio.h>  
 int main()  
 {  
     printf("Hello Tutorialandexample");  
     return 0;  
 }   

Output:

Compilation Process in C language

In the above flow diagram, the following steps are taken to execute a program:

Compilation Process in C language
  • First, the input file is transferred to the preprocessor, i.e., hello.c, and then the preprocessor transforms the source code to extended source code. The expanded source code extension will be hello.i.
  • The expanded source code is transferred to the compiler, and this expanded source code is converted to assembly code by the compiler. The assembly code extension will be a hello.s.
  • It then sends this assembly code to the assembler, which transforms the assembly code into object code.
  • When an object code has been developed, the linker generates the executable file.

 

 


Related Topics

Explain the two-way selection in C

In C programming, a two-way selection statement is used to choose between two different options based on a Boolean expression. The two-way selection statement in C is the if statement. The...

6 minutes read.

Dangling pointers in C

Dangling pointers in C: A pointer is a variable that stores the memory address of other variables. The pointers may also store the address of other’s memory items. They are...

4 minutes read.

Find Union and Intersection of Two Arrays in C

Union You can find the union of the two sorted arrays using the join merge method on arr1[] and arr2[]. Use two index variables i and j with initial values i =...

4 minutes read.

Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling

In this article, you will learn how to initialise an array to 0 in C In C, an array is declared as: char ZEROARRAY[2022]; The global scope changes at runtime to all zeros....

3 minutes read.

C Pointers

Pointers in C A pointer is a variable, which contains the address of another variable, i.e., it’s a variable which has the address of another variable as its value. The utilization...

4 minutes read.

How to use Typedef Struct in C

The “typedef” is a predefined keyword in C programming language which is used to declare the new name to an existing type of variable. For better understanding, if you declare a...

3 minutes read.

How to get ASCII value in C

For text data on computers and the internet, ASCII (American Standard Code for Information Interchange). It is the most widely used character encoding standard. One hundred twenty-eight alphabetic, numeric, special...

3 minutes read.

getch() function in C

getch() is a pre-define or built-in function present in the conio.h library. It returns the given character immediately without waiting for the enter key to be entered. By using getch()...

3 minutes read.

strtok() and strtok_r() functions in C with examples

strtok() and strtok_r() functions in C with examples C offer various strtok() and strtok r() methods for a string to be separated by a certain delimiter. Dividing a string is a...

2 minutes read.

While Loop Syntax in C

What is Loop? The statements in the sequence are repeatedly executed via looping statements in C until the condition is met. The body of a loop and a control statement make...

4 minutes read.

Exponential() in C

Introduction: In C language, there are available many types of functions. The exponential() function is one of them. It is a mathematical function. This article describes using the pow() property to...

3 minutes read.

Consumer billing system in C

Introduction : Billing has always been taught to do perfectly, we know today's world is full of products, and We all are using multiple products. We are buying and selling various...

9 minutes read.

Limitations of Synchronisation and Uses of Static Synchronisation in Multithreading

The multithreading component of java is the element around which the idea rotates as it permits simultaneous execution of at least two program pieces for the most significant usage of...

9 minutes read.

Library Functions in C

What are library functions? Library functions are the built-in functions (functions provided by the system) which are stored in the library. The library is the common location where these functions are...

3 minutes read.

Assert() Function in C

Assert (): In C, the statements are executed with the exit statement. In C language declare, and it tests the condition parameters. If the statement executed will be false, it shows...

4 minutes read.

Variables in C

A variable can be defined as a name allocated to a storage space that can be manipulated by our programs. Every variable in C arbitrates about the overall layout and...

5 minutes read.

Keywords in C

A keyword is a word that has a predetermined meaning. The C compiler knows the purposes of the keywords. The objectives of these keywords cannot be modified. Keywords are the...

9 minutes read.

Flow Chart of Do while loop in C

This is a flowchart that represents the process of executing the Do while loop in the C programming language Generally, as we know there are three main components of Do While...

3 minutes read.

Volatile in C

Introduction A volatile keyword is a qualifier in C. Qualifiers are nothing but keywords which are used to modify the properties of a variable. Qualifiers are of two types: 1) Const The const type...

3 minutes read.

Find Day from Day in C Without using function

Introduction: In the given article, I find daily in C without using functions. It takes 365 days for the earth to revolve around the sun. It will be close to...

3 minutes read.