Phase of C Program Compilation

In a C program we have four steps of compilation

This is the first phase of any C compilation. Its processes included files called file inclusion, conditional compilation instructions, and macros.

It converts C source code in expanded source code or a high-level language into pure high-level language.

It is the second phase. It takes the output of the preprocessor that is a pure high-level language and generates assembler source code.

It is the third stage of compilation. It takes the assembly source code and produces a relocatable code which is called an object or machine file which is of the same name as that of the program with extension dot o(.o).

Every machine has a different architecture, so the input fed to each machine should be understood by the machine and the compiler does not worry about that point. So it’s the assembler that makes the compiler machine-independent.

Using a Loader program, the executable code is loaded into CPU for execution. In the assembler phase, a relocatable code is generated. This is the responsibility of the loader to load the code at the proper place on the machine.

For example: Say in the code we have goto statement( goto 100) which is nothing but 100th line in the code but in the machine this may be present at address 1000, so it is responsibility of the loader to change these address. So loader is the one which correct these addresses.

It is the final stage of compilation. It takes one or more object files or libraries as input and combines them to produce a single (usually executable) file or a new library.

Multiple units of object codes are linked to together in this step.

And finally, the executable is executed or run to get the desired result.

hello_world.c -> Preprocessor -> hello_world.i -> Compiler -> hello_world.s -> Assembler -> hello_world.o

Diag-1: Phase of C compilation

Relevant Posts:

Categories: C Language

3 replies


  1. Compile and run a C program - Tech Access
  2. Features of C programming language - Tech Access
  3. Introduction to C Programming Language - Tech Access

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: