What happens when you use gcc in C ?

Thibaut Bernard
3 min readSep 16, 2020

--

Today i’m gonna talk about the compilator gcc for C language, i will explain you what does in a small details gcc, what is the preprocessor, what is the compiler, what is the assembler and what is the linker.

So the compilator gcc is decomposed in 4 process during the moment your enter the command with your file.c, like this :

the command with the file name in c

After you enter this command with your file, the first process in the compilator is the preprocessor:

The preprocessor

So what does the Preprocessor, the preprocessor will read your file and more particulary the header like “#include”, the comments you make in your file. It will “delete” theses comments and will link the file for the header you wanted. If you want to see this proceress with your file you juste need to use this command :

gcc with the parameters -E

After that, the second process in our compilator is the compiler:

Second process, the compiler

This process will transform your code into an assembly code, it will check also if there is errors in your code.

The assembly code

The parameters to gcc to see this process to your code is :

gcc with parameters -S

The third process of the compilator is the Assembler,

The assembler

It will take the assembly code from the last process and will convert the assembly code to an object code, which is a compiled code that can be run on any computer with the same CPU architecture, the object code is like this :

Object code

To see this process with your file, use this parameter with gcc :

The parameter -c

And the last process of the compilator is the Linker,

The linker process

This process will combine all the object code and combine the librairies you needed for execute your file and will create an executable. This executable can be execute like this (by default) :

default executable name

It’ll will run your program.

If you want to create a specific name for your executable you can use this parameter with gcc:

parameter -o for create your own name executable

So, now you know all the process of the compilator gcc, i hope you learn something from this article.

Stay tuned.

--

--

Thibaut Bernard
Thibaut Bernard

Written by Thibaut Bernard

Software engineer student at HolbertonSchool 👉https://github.com/ThibautBernard 👉https://twitter.com/__ThibautDev

No responses yet