The Translation Phases
suggest changeAs of the C 2011 Standard, ยง5.1.1.2 Translation phases, translation from source to a program image occurs in 8 ordered phases. C23 removes trigraphs, so phase 1 no longer replaces them; the other phases are the same idea.
- The source file is mapped to the source character set if necessary. In C11 and C17, trigraphs are replaced in this phase.
- Continuation lines, those that end with a backslash immediately before the newline, are spliced with the next line.
- The source is decomposed into preprocessing tokens and whitespace. Each comment is replaced by one space.
- The preprocessor is applied, which executes directives, expands macros, and applies pragmas. Each source file pulled in by
#includeundergoes translation phases 1 through 4 (recursively if necessary). All preprocessor related directives are then deleted. - Source character set values in character constants and string literals are mapped to the execution character set.
- String literals adjacent to each other are concatenated.
- The source code is parsed into tokens, which comprise the translation unit.
- External references are resolved, and the program image is formed.
An implementation of a C compiler may combine several steps together, but the resulting image must still behave as if the above steps had occurred separately in the order listed above.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents