Menu

Translators

Compilers

A compiler is a translator that converts a whole program into machine code in one go, before any part of that program is run. You hand it the source code you wrote, it translates all of it in a single pass, and then it stops.

A compiler translates the whole source code in one pass; if there are errors they are all listed together and must be fixed and recompiled, otherwise the object code is saved and run directly by the processor.

What comes out of a compiler

The compiler's output is object code. You may also see this called machine code, an executable or a binary — those names all describe the same thing: instructions that a processor can carry out directly. Because object code is a file, it can be saved to storage and run later, on a computer that has no compiler installed. Once a program has been compiled, the person using it only needs the executable.

Why compiled programs run quickly

All the translation work has already been finished, so when the executable is opened the processor simply carries out instruction after instruction. Nothing has to be converted while the program is running. A compiled drawing app, for example, responds the instant you drag the mouse, because the job of turning the source code into instructions happened earlier, not now.

Errors, processors and edits

A compiler reports nothing until it has translated the entire program, then lists every error it found together at the end. Nothing can be run until the program compiles with no errors, so you fix them all and compile again.

Object code is written for one type of processor. A program compiled on a laptop with one kind of processor will not necessarily run on a tablet with a different one — it has to be compiled again for that machine.

Any edit to the source code means the program must be recompiled before the change takes effect. Until you do, the saved executable still contains the old version of the program.

Practise this