What happens when you type gcc main.c?

GCC, short for GNU compiler collection, is a compilation program that takes your high-level (human language) code and translates it into low-level machine code (binary). It consists primarily of 4 individual modules:

  • Preprocessor — removes any comments and translates macros (if any) into code
  • Compiler — translates the code into assembly code
  • Assembler — translates the assembly code into object code
  • Linker — links our output with the necessary library

But what does all that really mean?

The preprocessor takes your files (in our diagram, both .c files) and creates a new file of extension ‘.i’. These files have undergone the process described above and are free from comments and macros have been translated. This preprocessor now feeds these new files as input for our compiler. The compiler then takes that input and translates it into assembly code. Assembly code is simply a mnemonic language which gives the computer a set of human-language instructions. Now with the easily digestible assembly code, our assembler is ready to interpret these newly generated .s files and translate them into object code (.o). Finally, this machine code generated by our assembler finds it’s way to the linker which essentially combines everything we need into one neat little .exe file.

Through this process we have walked through the steps a computer takes from starting with a plain text main.c file all the way through compilation until it arrives at it’s .exe destination.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Access android GPS Location using Python

Docker installs percona and solves the crash problem

Rage On Wheels gameplay: PvP mode

Deno by example: Content server — Part 4 Integration & Performance testing

Pyspark Joins — Explained

INTRODUCING GOMINT — Problems & Solutions

Each line of code feels like the stroke of a brush…

My Hackathon Journey

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gabriel Vazquez

Gabriel Vazquez

More from Medium

Bucket Sort

“It doesn’t cost money, but it does cost time” —How to improve UK recycling rates

How PMM Algorithm Works?

Nine months later…