In order to understand how our program works, it is important to know how the Compiler turns your code into a program. When you press the "Compile" button, your program goes through a three part process:
The Pre-Processor removes all comments from your code and runs any Pre-processor Commands you have written.
The Compiler turns each file of code (.c) into object code (.o), which computers can read but humans can"t.
The Linker takes the object code files and combines them into one executable file (.exe) which can be run.
We're going to look at each part of the Compiling process and see what it does to the "Hello World!" project:
Here's what the Pre-Processor does with our project:
It copies the #included .h files into the C files.
It removes all of the comments.
It replaces the constant THE_OUTPUT every time it appears in the code.
Notice that the files that come out of the Pre-Processor are C files that we could read or write if we wanted to. Also, we don't need hello_func.h anymore, all that code is now in main.c!
Next we'll send our program through the Compiler. The Compiler has two steps:
It turns our C code into Assembly (a language that is very hard to write)
It turns the Assembly code into Object Code (Which people cannot read at all)
The final part of the process is the Linker:
It will combine the Object Code into one file.
It will add in code from libraries like stdio
It will make sure that every function that is called has been defined in one of the C files.
It will create an executable file that the computer can run.