번환의 단계
C++ 소스 파일은 정확히 아래의 단계와 같이 컴파일러에서 처리됩니다.
단계 1
'0'부터 '9'까지'a'부터 'z', 그리고 'A'부터 'Z'까지_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '\u or \U) or by some implementation-defined form that is handled equivalently.|
3) Trigraph sequences are replaced by corresponding single-character representations.
|
(until C++17) |
단계 2
\uXXX) is formed in this phase, the behavior is undefined.단계 3
<iostream>와 "myfile.h"같은 헤더 이름들(#include 이후에 적혀있는 것들만)|
2) Any transformations performed during phases 1 and 2 between the initial and the final double quote of any raw string literal are reverted.
|
(since C++11) |
Newlines are kept, and it's unspecified whether non-newline whitespace sequences may be collapsed into single space characters.
단계 4
단계 5
Note: the conversion performed at this stage can be controlled by command line options in some implementations: gcc and clang use -finput-charset to specify the encoding of the source character set, -fexec-charset and -fwide-exec-charset to specify the encodings of the execution character set in the string and character literals that don't have an encoding prefix (since C++11).
단계 6
Adjacent string literals are concatenated.
단계 7
Compilation takes place: each preprocessing token is converted to a token. The tokens are syntactically and semantically analyzed and translated as a translation unit.
단계 8
Each translation unit is examined to produce a list of required template instantiations, including the ones requested by explicit instantiations. The definitions of the templates are located, and the required instantiations are performed to produce instantiation units.
단계 9
Translation units, instantiation units, and library components needed to satisfy external references are collected into a program image which contains information needed for execution in its execution environment.
Notes
Some compilers don't implement instantiation units (also known as template repositories or template registries) and simply compile each template instantiation at Phase 7, storing the code in the object file where it is implicitly or explicitly requested, and then the linker collapses these compiled instantiations into one at Phase 9.
참조
- C++11 standard (ISO/IEC 14882:2011):
- 2.2 Phases of translation [lex.phases]
- C++98 standard (ISO/IEC 14882:1998):
- 2.1 Phases of translation [lex.phases]
See also
C documentation for phases of translation
|