Tuesday 3 March 2015

Steps in Developing a Program in C


A programmer uses a text editor to create and modify files containing the C source code. A file containing source code is called a source file (C source file s are given the extension .c). After a C source file has been created, the programmer must invoke the C compiler before the program can be executed. If the compiler finds no errors in the source code it produces a file containing the machine code (this file referred as the executable file).
The compilation of a C program is infact a three stages process; preprocessing, compiling and linking.

                                         

Preprocessing is performed by a program called the preprocessor. It modifies the source code (in memory) according to preprocessor directives (example: #define) embedded in the source code. It also strips comments and unnecessary white spaces from the source code. Preprocessor does not modify the source code stored on disk, every thing is done on the copy loaded into the memory. Compilation really happens then on the code produced by the preprocessor. The compiler translates the preprocessor-modified source code into object code (machine code). While doing so it may encounter syntax errors. If errors are found it will be immediately notifie d to the programmer and compiling will discontinue. If the compiler finds any non-standard codes or conditions which are suspicious but legitimate it will notify to the programmer as warnings and it continues to compile. 

A well written program should not have any compilation errors or warnings. Linking is the final step and it combines the program object code with other object codes to produce the executable file. The other object codes come from run-time libraries, other libraries, or object files that the programmer has created. Finally it saves the executable code as a file on the disk. If any linker errors are encountered the executable file will not be generated.


No comments:

Post a Comment