There are different phases through which our program passes before being transformed into an executable form.
Preprocessor
When a C program is written, it must be typed into the computer and saved to a file. A text editor, which is similar to a word-processing program, is used for this task. The statements written by the programmer are called source code, and the file they are saved (with an extension '.c') in is called the source file.
This source code is firstly passed through the preprocessor. The preprocessor is responsible for
- Removal of comments
- Expansion of Macros
- Expansion of the included files.
Compiler
The compiler converts source code into the machine's assembly language code. The source code is received from the preprocessor.
Assembler
This assembly language code is converted to object code by the system's assembler. The name of object file is same as that of source file. In DOS the object file has extension '.obj' and in UNIX the extension is '.o'.
Linker
Generally all programs written in C, use library functions. Library functions are precompiled and their object code is stored in library files with '.lib'(or '.a') extension. The linker combines this object code of the library functions with the object code of our program. Our program may also contain references to functions that are defined in other files. The linker links the object code of these files also to our program. So the job of the linker is to combine the object code of our program with the object code of other files and object code of library functions. The output of the linker is an executable file. In DOS the executable file has same name as that of source code file and has extension '.exe', and in UNIX the executable file is named as a.out or the name of output with -o option.
No comments:
Post a Comment