Previous: 2.2 Organization of C Programs - Simple Statements
Up: 2 Basic Concepts
Next: 2.4 Input: Reading Data
Previous Page: 2.2.5 Generating Output
Next Page: 2.3.1 Debugging the Program
As mentioned, the above program must be typed using an editor and saved in a file which we have called pay0.c. The program in C, a high level language, is called the source program or source code. It must be translated into the machine language for the particular computer being used. The machine language program is the only one that can be understood by the hardware.
A special program called a compiler is used to compile, i.e. translate a source program into a machine language program. The resulting machine language program is called the object code or object program. The object code may be automatically or optionally saved in a file. The terms source file and object file refer to the files containing the corresponding source code and object code.
The compiled object code is usually still not executable. The object code needs to be linked to machine language code for certain functions, e.g. code for library functions such as printf(), to create an executable machine language code file. A linker or a link editor is used for this step of linking disparate object codes. The linking step is usually automatic and transparent to the user. We will refer to the executable code variously as the object code, the compiled program, or the load module.
The executable code is then loaded into memory and run. The loading step is also transparent to the user; the user merely issues a command to run the executable code.
For many systems, the convention is that the source file name should end in .c as in pay0.c. Conventions for object file names differ; on some systems object files end in .obj, on others they end in .o, (Consult your system manuals for details). For compilation and execution, some systems require separate commands, one to compile a C program and the other to execute a compiled program. Other systems may provide a single command that both compiles and executes a program. Check your operating system and compiler manuals for details.
For Unix systems, the cc command, with many available options, is used for compilation. Examples are:
cc filename.c
cc -o outname filename.c
The first command line compiles the file filename.c and
produces an executable file a.out.
The second directs that the executable file is to be named outname.
These programs are then run by typing the executable file name to the shell.