This happens when you type gcc main.c. Totally not written by Gucci Mane.

“Why yes, I do know what happens when a file goes through gcc.”

TL;DR:

Terminal input command:

gcc [filename]

PREPROCESSOR

First, the file goes through the preprocessor where the code from header files (like #include <stdio.h> or #include “custom_library_file”) are placed into the output file. Your file just got a bit larger.

COMPILER

Second, the file goes through the compiler where all the code in the file is translated to assembly code:

C code on the left, Assembly code on the right. Assembly code is a list of of instructions to the computer.

ASSEMBLER

Third, the file goes through the assembler where the assembly code is translated into binary machine code: those 0s and 1s .

LINKER

Finally, the file goes through the linker where machine code from all the files put through the gcc are placed together in one executable file. So it’s not relevant when we’re only compiling one file. However, it’s rarely the case that you’ll write C without header files, which means the linker always has a vital job.

OUTPUT

The output is an executable file called “a.out”. It’s only called “a.out” because that is the default name of the output file when the name of the output file isn’t specified in the gcc command.

If we wanted to specify the name of the output file, use this command next time:

gcc [source file] -o [output file name]

And that’s how it’s done!

--

--