Compiling in C

Ariana Bibiano
2 min readSep 19, 2019

--

The first C program

What is C?

C is a general-purpose programming language that is not tied down to any one operating system or machine and because of this it has been used to write many compilers, operating systems, and other major programs such as JavaScript and Python.

What is a compiler?

C programming uses the gcc compiler and gcc stands for GNU Compiler Collection. A compiler is used for translating source code that’s typed by a human, into machine code, which is what the computer reads, in order to process it. There are four stages of compiling a C program: preprocessing, compiling, assembly, and linking.

Preprocessing:

The preprocessing stage is when the compiler takes the source code and removes all of its comments which are usually indicated by a # or /**/. Source code is written in plain text and they’re saved as .c file name extensions.

Compiling:

The next stage is compiling. This step translates the source code into intermediate human readable language, through assembly instructions specific to the target processor.

Assembly:

The following stage is assembly, and in this part the the assembler converts assembly code into machine code. Machine code is also known as object code and they end with the .o filename extension.

Linking:

The final step of compilation is linking. And in this stage the linker combines the object code generated in the assembly stage with library functions taken from the source code into an executable program. When this final step is run without the -o script it automatically creates a file named a.out.

And as we can see the output is the file a.out. The reason that it’s green as opposed to white is because a.out is now an executable file. And an executable file is exactly what we should get when a .c file is compiled correctly.

--

--