What is Compilation Stages?
Consider a simple program hello.c
#include<stdio.h>
int main()
{
printf(“hello, computer\n”);
return 0;
}
Compilation stage image-1 |
The first work or action is to activate a preliminary or opening process called the initialization or pre-processor. In the case of hello.c all it does is to return or replace the line #include <stdio.h> with the file stdio.h from the cover or include files library. The file stdio.h provides or gives us with a suitable or convenient way of telling the author or compiler that all the i/o task or functions exist. There are a few other little item or things in stdio.h but they need not cover or concern us at this stage.
In order to see what the initialization or pre-processor actually outputs, you might like to topic or issue the command:
cc-E hello.c – o hello.i
The ‘cc’ command will operate or activate the ‘C’ compilation or collection system and the –E option will stop the collection or compilation process after the pre-processing stage, and another file will have look or appeared in your directory. Have a look, find hello.i and use the editor in view method or mode to have a look at it. So issue the command:
vi hello.i
You will see that a number of lines of work or text have been added at the front of the hello.c plan or program. What’s all this matter or stuff? Well, have a look in the file called /usr/include/stdio.h again using the view instruct or command.
vi /usr/include/stdio.h
Now the next period or stage of getting from your program text to a perform or executing plan or program is the collection or compilation of your text into an assembler code program. After all that is what a editor or compiler is for – to turn a high level language script into a plan or program.
Let’s see what happens by issuing the instruct or command
cc –C hello.s –o hello.o
Now, yet again there is another file in your index or directory – this time the suffix is “.o”. This file or folder is called the object file. It carry or contains the machine command or instructions keep in touch or corresponding exactly to the help or mnemonic codes in the .s file. The next stage in the collection or compilation process is called by a diversity or variety of names –“loading”, “link editing”, “linking”. What happens is that the tool or machine instructions in the object file (.o) are joined to many more order or instructions selected from a huge or enormous collection of functions in a library.
Computer stuff kit tricks of Topics 65.
What is C Preprocessor in C language?