Compiler for C programming language
What exactly is a computer program? I doubt there is anyone who cant come up with answer to that question,. Everyone uses smart phones, apps, and the internet enough to at least know that they are programed by developers with the intention of running on computers.
There may even be some enlightened souls who may even know of the existence of the various CPU languages that are used to write code however in most cases that is where the general knowledge stops.
Programs may be simple, like a basic calculator, or very complex like a CPU game, but no matter how big or small a program is they all share a similarity in that they are all written and compiled to be used on a device. What the user sees, usually accompanied by a catchy logo or design is called an executable file. Clicking on one of these files is what actually makes the program run. we will look at the process that creates this executable files which all programs, great or small all share.
Compiling in C requires four major steps despite the fact that we only see 1 output and that's the ".c" file or the executable.
The Four steps are as follows
Pre processing
After the extremely simple or extremely complex code is written, its time for the pre processing stage. In this stage, any if or else logic is compilated, comments are removed, include files and , macros are expanded (fancy way of saying objects are broken down to there smallest components. The entire process produces a ".i" file type. The additional libraries and header files are included in the process. These external libraries are extremely important because they contain the functions that work behind the scenes and actually make the code work.
The header #include <stdio.h> is what allows a programmer to output text onto the screen. It includes the logic for the printf() function and without the CPU would not know what that function means
At times the pre processor step is looked at as just a substitution tool as it doesn't actually convert anything it just sorts things out and gets all the values in 1 place. However this is an important part of the process because it allows for the compiler to do its job without a hitch. Without the addition of such libraries the developers who use C would have to write all the background code itself and the entire process would be prolonged. Pre processing is also another step in the error handling process to help with debugging for errors, this way CPU know if something went on before or during the compilation process.
Compilation
The next step is to take the previous file and compile it to produce an intermediate compiled output file ending in a ".s" file extension. The resulting file format will be in what is known as assembly level instructions. This is necessary so that the assembler in the next step can read the code. Of course in order to compile you need a compiler, one of the most popular of which is the gcc compiler which was originally written for the GNU operating system.
Assembly
Assembly language is the interference between high and low level code, a compiler transforms high level code into assembly code so that the assembler can do its job. Machines read code in a format called binary, these are the ones and zeros that you see filling up a screen on television shows and movies. The binary data represents the object code shown on the right
Assembly language is very similar to machine language, in this phase the file ending in ".s" is used an an input and the resulting file type is ".o". This file contains machine level instructions that is difficult for us to read (almost impossible) machines love it. At this point only the existing code is converted and function calls within the program are not resolved until a later step.
Linking
In the final step the linker compares the 3 file types that have been created:
Function calls are linked with their definitions and some extra code. The extra code is essential for setting up environmental functions and variables. All of these steps are conducted in the background when a programmer writes a complete program and pushes the compile button. If it compiles without errors the result will be an executable file that allows you to run the program.
The Build
With the final step Completed and excluding any errors that may have occurred, you now have a working program that will run as the developer intended. The entire process is referred to as a build. There are many different languages which include or require different libraries to carry out functions and run on different devices however every program must go through a similar compilation process before it can be used. The GCC compiler is one of the most popular but there are as many compilers as there are languages and GCC did not start of as the industry standard that it has become.
Although developers are accredited with the success of the technologies they create, its obvious that they don't do it alone. Without a compiler the extra code needed to compile a program would require more coding than the program itself! So the next time your at your desktop and you click on that familiar icon to open up your favorite application remember that there is a lot that went on behind the scenes that allows one simple mouse click to run a program.