ENES

Compiler

A program that translates source code into instructions a computer can run directly.

Source code goes into a compiler, which checks it, reports an error on one line, and otherwise produces machine code ready to run on a CPU

A compiler is a program that reads source code written in a language like C, Rust, Go or Swift and translates the whole thing, ahead of time, into machine code: the low-level instructions a specific kind of CPU executes. The result is a file you can run on its own, like the app you double-click, without the original source code or the compiler.

Along the way the compiler checks the code. If you call something that does not exist, pass text where a number is required or forget a bracket, it refuses to finish and points at the line. It also optimizes: it rearranges and simplifies the instructions so the program runs faster than a literal translation would. That is a big reason compiled programs tend to be fast.

The alternative is an interpreter, which reads the code and runs it on the spot, as Python and JavaScript traditionally do. In practice the line is blurry. Java and C# compile to an intermediate form that a virtual machine runs, and browsers compile JavaScript to machine code while the page is running (just-in-time compilation). Because machine code is specific to a processor family, the same program has to be compiled separately for, say, Intel and Arm chips.

Keep in mind

Go deeper

Related terms

More in Software