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

Fully on-chain trading bot using Balancer v2 pool

Professional Cloud Architect Certification

Generate allure report with behave

Up and running with Unity


Using Executor Service with Java 8 — Part II (Using List Partition)

BOSAGORA 소식, 빗썸에서 확인 가능

Why Isn’t My Kanban Working?

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

CS 373 Spring 2022: Yifan Zhou

CS373 Spring 2022: Abinith Thallam Week 11

CS371P Spring 2022: Daniel Cai