What happens when you type GCC main.c

Jimmy Thong
2 min readOct 13, 2016
Source

When you want to execute code to create an object file, the computer needs to be communicated with in machine language, which is (base-2) binary code. Unfortunately (and fortunately), humans communicate in language higher than binary. Hence, why we use a higher-level language like Python, Ruby, and in this case, the C programming language. But, in order for computers to execute our C code, we have to compile the code using the Unix command:

GCC main.c

Here’s what happens when we GCC the file main.c

Three main steps happen when we compile code:
1. Reads the source file
2. Processes it
3. Links it with a runtime library

A lot happens when the code is being processed. Let’s unpack.

A compiler has multiple modules: preprocessor, compiler, assembler and linker.

When we write the file main.c, the preprocessor generates some intermediate file, that file is given to the compiler. The role of the compiler is that it compiles files generated by the preprocessor as input, and that generates assembly code, so it can convert our C program file into the assembly language. Computers can only generate binary code, which is why assembly language is the format it needs to be in.

--

--

Jimmy Thong

Makerspace Teacher, Code Coach, Amateur Home Cook, Writer