When a program is written in a higher level language like 'C' that program must be translated into machine language so that it can actually be run on the computer. This process of translating a high level language to machine language (or perhaps assembly language in some cases) is called: compiling.
The program which does this translation is called a compiler. It accepts as input a text file which has statements written in the high level language and translates it into machine language, into what is called an Object file.
The first step in writing a program is to use a text editor or word processor to create one or more source files which contain the program to be compiled. This file, or files, are the input to the compiler which translates each one into an object file.
When a program is compiled from more than one source file, each of the source files (with its header, *.h, file - if any) is called a module. The compiler and the linker must be informed of the names of these files, as well as any files already in object form or any functions which must be extracted from the function library.
This two step process and looks like the following:
+--------+ ########## +----------+ ########## | Text | # Source # | | # Object # | |===># #===>| Compiler |===># # | Editor | # File # | | # File # +--------+ ########## +----------+ ##########
There are programming environments in which the:
Text Editor Compiler Linker (see later) Debugger (optional)
are all accessible through one coordinating program; for example, Borland's TurboC and Microsoft's Visual. Of course, all of these programming environments also provide for each step of the process to be done by a stand alone program.
An Object file is not a runable program, because usually there are some unresolved variables or functions (see: 'Program'). That is, a module and hence an object file may refer to one or more variables or functions which it does not have. The compiler was told that it was all right to reference these variables or functions, by declarations which specified their type and other attributes, but still the compiler does not know where in memory they will be. It will be the job of the Linker to resolve this. The job of the linker is discussed in the next lesson.
Before translating a program to machine language, a compiler has one more job to do. It must first determine that the program is grammatically correct. The compiler will give warning or error messages about things which are wrong or it is not sure about.
But if a compiler does not give any warning or error messages, that does not mean that the program is correct in the sense that it does what you want it to do. The compiler is not smart enough to know what you want to do. It can only translate what you asked to do into machine language.
When a compiler gives a warning message it means that something may be wrong. That is something other than you expect may occur. This is only a guess by the compiler. It is good programming practice and helpful to understand a language to take the steps to eliminate all compiler warnings. There is always a way to do this.
When this is done, any new compiler warning becomes a hint of a possible error in a program.