Compilation Process


Before discussing the actual compilation process let us discuss the c program structure of a typical c program which consist of the following component

.c files , standard c libraries , other c libraries


 
These components combined together to form a c program , let us now see what is the meaning of this components

.c files  -  it is the file that contains the source code , there could be a single c file or multiple .c files for a single program

Standard c library  -  all the definitions of functions like printf() , scanf() , puts() ,getch() etc are to be found in the standard c library , standard c  library contains pre compiled codes that we can use in our program to make software development faster

Other c library  -  it may be possible that we need some functionality in our program that is not available in the c standard library , in this case we can use libraries that are not of c standard library , for example  we may want to connect to a database using c program and for this  we may have to import a library for our database program

So that will be the structure of a typical c program , now let us examine the compilation process

The actual compilation process can be sub divided into three broad groups

Pre processing / pre compilation

Compilation

Linking

Let us examine the three processes in detail

Pre processing or pre compiling  -  it can be said as processing that happens before the compilation process  , during this process all the .c files are pre processed , sometime it is done in the memory and sometime it is done by creating a temporary file by the compiler ,In this process all the pre processor directive like #define , #include are processed as well as all the comments are removed

Compiling – during this process the coding is converted from human readable form to machine readable form and we get a object file , other things that happens in this process are syntax checking , prototype checking , variable checking etc

One thing to notice is that , if our program has only one c  source file then we may not get the object file and directly end up with the exe file

Linking – it is the final stage in which all the necessary file that will be the object file , c standard library files and other library files are linked together to form a executable file having a .exe extension




We have talked about c program structure and compilation process  , now we will  talk about memory regarding c programs

The memory can be divided into four groups

Static

Stack

Dynamic

Program

Let us examine the above in detail now

Static – all the global variable and static variables are stored in this part of memory , this memory is called when program is started and is destroyed when the program ends

Stack – all local variable and function parameter are stored in this part of the memory , the lifetime of these variable ends when the block that they are in ends

Dynamic – it is also called as heap memory , it is allocated by the operating system when required by the programmer , a pointer is used to use this memory

Program memory – this memory contains the object code of the executable file  , this memory is never modified during the course of execution



 

No comments:

Post a Comment