Skip to content
academia.sh

Unit 01 of 02

Language and Compilation

Which design decisions arise from the language's closeness to hardware, the four stages a source passes through on its way to becoming a program observed separately, declarations shared through header files, the text-level preprocessor knowing no types, and which standard compiler warnings are born from.

Published Updated

Lessons

  1. 01 The Place of C In C, a source turning into a running program is not a single step: it passes through four stages, and each stage looks at a separate question. A three-file measurement core shows these four stages in a single run and writes 4 of fourteen observations to the preprocessor, 4 to the compiler, 3 to the linker, and 3 to runtime. 14 min read
  2. 02 Compilation Stages Each of the four stages looks at a different input: the preprocessor only text, the compiler a single unit, the linker multiple units, and runtime only data. A small measurement excerpt runs all four side by side; a separate pair of programs also shows how one line of the same source enters two different compilations, through a decision made in the source beforehand. 14 min read
  3. 03 Header Files A header file does not carry a name, it carries that name's text, and the preprocessor copies it separately into every unit that uses it. This makes it possible for the same declaration to enter two units at once and for both to compile; the measurement proves this by running it, and separately shows what the include guard prevents. 14 min read
  4. 04 The Preprocessor The preprocessor's four different directives — macro value, conditional body, token pasting, inclusion — are in fact four appearances of a single job: text substitution. Because a macro knows no types, it produces the same expression so that it gives the correct result with two different types; but because it can substitute its argument more than once, it can run a call with a side effect a different number of times than a real function would. 13 min read
  5. 05 Compiler Warnings and Standards A warning can only be born at the compiler stage, because only that stage sees the types and expressions inside a single unit. What the standard guarantees is set side by side with what it leaves to the implementation — sizeof(char) == 1 is a guarantee, other sizes are not. Nor can a program that compiles without a warning be said to be correct; to show this, a computation that prints no warning but produces a wrong result is run. 14 min read

Start typing to search.

↑↓ ↵ Esc navigate · open · close