LIFE-CYCLE OF C PROGRAM
There are at least five phases of execution of  a C language program:-
1. Pre-Processing
2. Compilation
3. Linking
4. Loading
5. Execution



 

Pre-processing:-

Pre-processing is under control of pre-processor directives. It is a program which will be executed automatically before passing the source program to compiler. The pre-processor statements are processed first. All the statements starting with # (pound) symbol are called pre-processor statements. Pre-processor is not a part of C compiler. After pre-processing, there generates a file with .I extension file.(read header file and #include article – coming soon).

Compilation:-

The grammatical rules or syntactical validity of the complete program is checked. If there is any error, the location and type of error is reported to the programmer. These are called syntax error.
If there is no error, then the compiler generate object code and prepare symbolic table. So we can say that compilation is a process to check syntax error and converting high-level programming language code into machine readable format i.e. object code format. The object code is a binary format file.
In compilation phase a data structure symbolic table is prepared. It contains the detailed information of all the identifiers declared in the program. This symbolic table is used throughout the execution of the program. Some major fields are:-
  • Name of identifier
  • data type information
  • Length in bytes
  • Relocatable memory address.
  • And many more useful information
The compiler some times reports warning also. We should not ignore warning.
Some common syntax errors can be:-
    • Semicolon required
    • Identifier not declared
After compilation, compiler generates .obj file.

Linking:-

Linking is a process of combining all .obj files of current program along with standard lib or obj files to create an executable file called .exe.
Symbolic links are resolved in this phase. A function call is called symbolic link. There are many function calls in our program. The function may a be pre-defined(available in library files) or user defined functions. These functions are stored in a separate memory area. The linker substitutes the name of the function with the address of the first instruction of the function.

Loading:-

Loading is a process of carrying .exe file into primary memory i.e. RAM. Loading is under the control of OS.

Execution:-

The instructions of the object code are executed one by one it has four major steps:-
1. Instruction fetch
2. Operands fetch
3. Instruction decode
4. Instruction execution

Summary
The compilation and execution process of C can be divided in to multiple steps:
·         Preprocessing - Using a Preprocessor program to convert C source code in expanded source code. "#includes" and "#defines" statements will be processed and replaced actually source codes in this step.
·         Compilation - Using a Compiler program to convert C expanded source to assembly source code.
·         Assembly - Using a Assembler program to convert assembly source code to object code.
·         Linking - Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
·         Loading - Using a Loader program to load the executable code into CPU for execution.



Comments

Popular posts from this blog

what is shell in linux

PL/SQL - Triggers