KOL and MCK

A reference on Object Pascal, the Delphi line and the libraries built on it.

Pascal

Why the Compiler Read the File Once and Stopped

KOL and MCKPascal

Person typing on a keyboard facing two old CRT monitors displaying text and code

One pass over the source and no intermediate file a user ever saw. The speed was the product.

A Design Decision Wirth Made Structural

Pascal's syntax was not accidentally compatible with single-pass compilation — Niklaus Wirth built the constraint in deliberately. A single-pass compiler reads each source file exactly once, top to bottom, resolving every identifier at the moment it appears. That discipline demands something in return: any identifier used before its definition must be declared in advance. Pascal formalised this as the forward declaration, a named stub that tells the compiler a procedure exists and what its signature looks like, with the full body to follow.

The structural bargain is tight. Because every type, variable and routine must be declared before use — and because the language's block structure, inherited from ALGOL 60 ↗, enforces strict ordering of declaration sections — the compiler never needs to hold the entire program in memory waiting for a second pass to resolve references. It can emit code, or at least intermediate form, as it reads. The grammar and the compiler architecture are the same argument.

Niklaus Wirth photographed at ETH Zürich, or a printed Pascal program listing on fanfold paper under a desk lamp

Pascal's declaration-before-use rule is legible in any listing: every type and variable is named before the statements that touch it.

A conference room at a Delphi-era developer event, projector displaying a code slide, adult audience members seated, speaker at the front

Delphi-era developer conferences were where version changes got argued out in front of the people who had to migrate.

Photo: Matheus Bertelli / Pexels

Borland International understood the commercial consequences. When Anders Hejlsberg wrote the Turbo Pascal compiler, the single-pass architecture meant compilation speeds that contemporaries found almost implausible — whole programs measured in thousands of lines compiled in seconds on hardware that could barely spare the memory for the source text. The speed was not a tuning achievement; it was a consequence of the language's shape. Turbo Pascal's 1983 release made that speed the product's most visible feature, and it was the grammar that permitted it.

The price shows clearly when two procedures call each other. Without a forward declaration for the first, the compiler reaches the call to the first and has no record that it exists. Pascal resolves this with the forward directive: the first procedure's header is declared forward, the second is defined in full, then the first's body follows. The compiler never looks backward; the programmer arranges the file so it never needs to. That arrangement — the programmer serving the compiler's single-direction read — is the honest statement of what single-pass compilation costs.

Later Turbo Pascal releases introduced the unit model, with its explicit interface and implementation sections, which extended the same logic across separately compiled modules. The interface section is, in effect, the file's own forward declaration ↗ to the world outside it: every public identifier announced before any implementation detail is revealed.

More in Pascal

All of Pascal