Skip to content

编译器

一句话解释

编译器是 program 那个 translates 源 code 到 machine code 所有 at 一次, 之前 program 运行.

用大白话说

A compiler is a special program that takes your source code (written in a language like C, C++, or Java) and translates it entirely into machine code — the binary instructions the CPU can execute directly. This translation happens before the program runs.

The advantage of compilation is speed: since the code is pre-translated, the program starts and runs fast. The disadvantage is that you must recompile every time you change the code, which slows down development.

Compiled languages include C, C++, Rust, Go, and Java (compiled to bytecode). Each has its own compiler: gcc for C, javac for Java, rustc for Rust. The compiler also catches syntax errors before you run the program, giving you a chance to fix them.

示例

bash
# Compile a C program
$ gcc program.c -o program

# Run the compiled program
$ ./program
Hello, World!

gcc 编译 program.c 到 executable called 'program'. 你然后运行 executable directly.

常见混淆

  • 容易混淆的对象: 解释器

    关键区别: 编译器 translates 所有 code 之前运行 (faster execution, slower development); 解释器 translates 行-通过-行 at 运行时 (slower execution, faster development).

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表