A compiler takes the source code as a whole and translates it into object code all in one go. Once converted, the object code can be run at any time. This process is called compilation.
All of the object files used in a program must be combined before the program can be run. This is done using a linker tool, which takes one or more objects and groups them into a single executable or a library.
Compilers have several advantages:
Compiled programs run quickly since they have already been translated.
A compiled program can be supplied as an executable file. An executable file is a file that is ready to run. Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code.
Compilers optimise code. Optimised code can run quicker and take up less memory space.
Compilers have several disadvantages:
Because the source code is translated as a whole, there must be enough memory space to hold the source code, the compiler and the generated object code. There also needs to be temporary working space for the compiler to perform the translation. Modern systems either have enough memory or use virtual memory to hold all the data.
Compilers do not usually spot errors - the program has to be compiled and run before errors are encountered. This makes it harder to see where the errors lie.
The source code must be recompiled every time the programmer changes the program.
Source code compiled on one platform will not run on another - the object code is specific to the processor's architecture.