Quiz Entry - updated: 2026.07.14
What are the stages in transforming source code to executable machine code?
Four stages: preprocess (-E) → compile to assembly (-S) → assemble to an object file (-c) → link into an executable (-o).
* GCC transforms source into an executable in four stages, each producing an intermediate file until the linker emits the runnable program. *
| Stage | Input | Output | Tool |
|---|---|---|---|
| Preprocessing | Source code (.c) | Preprocessed source (.pp.c) | gcc -E |
| Compiling | Preprocessed source | Assembly code (.s) | gcc -S |
| Assembling | Assembly code | Relocatable object code (.o) | gcc -c |
| Linking | Object files | Executable | gcc -o |
What each stage does:
- Preprocessor: Expands #include, #define macros
- Compiler: Translates C to assembly language
- Assembler: Converts assembly to machine code (binary)
- Linker/Loader: Combines object files, resolves external references, adds the C runtime, and produces the final loadable executable
Tip: Remember "PCAL" - Preprocess → Compile → Assemble → Link. The flags follow the same pattern: -E, -S, -c, then -o for output.
Go deeper:
Compiler (Wikipedia) — the front/middle/back-end pipeline, situating the preprocessor, assembler and linker as the toolchain stages that turn source into an executable.