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:

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.



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