The program which is to be compiled is first typed into a file on the computer system. If the Operating System is UNIX then using VI editor, the file can be opened. The program that is entered into the file is known as the source program since it represents the original form of the program expressed in the C Language. Once the source program has been into a file, we can then proceed to have it compiled. The compilation process is initiated by typing in a special command on the system. When this command is entered, the name of the file that contains the source program must also be specified. Under UNIX OS, the command to initiate program compilation is called c. Typing the line cc sample_program.c
would have the effect of initiating the compilation process with the source program contained in sample_program.c.
In the first step of the compilation process. the compiler examines each program statement contained in the source program and checks it to ensure that it conforms to the syntax and semantics of the language. If any mistakes are discovered by the compiler during this stage. then they will be reported to the user.
Each statement is translated into an equivalent statement in assembly language by the compiler. The next step is the translation of assembly language statements into actual machine instructions. This step involves the execution of a separate program known as assembler. The assembler takes each assembly language statement and coverts it into the binary format known as object code, which is then written into another file on the system. This file will have the same name as the source file name with the extension "O" instead of a "C". After the program has been translated into object code. it is linked to transform the program into final form for execution on the computer.
If the program uses other programs that were previously processed by the compiler, then during this phase. the programs are "linked" together. Programs that are used from the system's program "library" are also searched and linked together with the object program during this phase.
The final linked file which is in an executable object code format. is stored in another file on the system, ready to be run or executed. In UNIX environment. this file is known as a.out.
So, the command a.out would have the effect of loading the program called a.out into the computer's memory and initiating its execution.
Each statement in the program is executed sequentially. I the program is in need of input from the user. It will temporarily suspend its execution so that the input may be entered. Results that are displayed by the program, known as output is displayed at the terminal from which the program was executed.