gcc main.c, explained

Andrew Lindburg
2 min readSep 12, 2018

--

gcc main.c is a command you can run on a Unix based OS. What it does is compile a C source code file named main.c into the gcc compiler’s default executable file names a.out.

This show the layers of abstraction that comprise a gcc compiler

However, we also must take a look under the hood. Several forces are at work behind the scenes when we compile a C file.

First off, there is the C Preprocessor. This will take whatever is in the header and adds appropriate code corresponding to its contents. For example, if #include <stdio.h> is in the header the preprocessor will add code that pertains to standard input/output for C.

Next, the compiler compiles the file into assembly code. This file will have a grammar that simplifies machine code instructions to basic English. These instructions are still human readable but they are specifying instructions for the machine to run the program.

Lastly, the assembler translates the assembly code in object code. These instructions are not human readable and are run by the machine.

Another thing that happens during the compilation process is the linker combines one or more object files generated into a single executable file.

--

--