C++ 程序的编译阶段是否由标准规定?
Are the stages of compilation of a C++ program specified by the standard?
如果有,它们是什么?
如果没有,一个广泛使用的编译器的答案(我更喜欢 MSVS)会很棒.
If not, an answer for a widely-used compiler (I'd prefer MSVS) would be great.
我说的是预处理、标记化、解析等.它们的执行顺序是什么?它们具体做什么?
I'm talking about preprocessing, tokenization, parsing and such. What is the order in which they are executed and what do they do in particular?
我知道编译、链接和预处理的作用,我最感兴趣的是其他和顺序.当然,也欢迎对这些进行解释,因为我可能不是唯一对答案感兴趣的人.
I know what compilation, linking and preprocessing do, I'm mostly interested in the others and the order. Explanations for these are, of course, also welcomed since I might not be the only one interested in an answer.
C++ 程序的编译阶段是否由标准规定?
Are the stages of compilation of a C++ program specified by the standard?
是和否.
C++ 标准定义了 9 个翻译阶段".引用 N3242 草案 (10MBPDF),日期为 2011-02-28(在官方 C++11 标准发布之前),第 2.2 节:
The C++ standard defines 9 "phases of translation". Quoting from the N3242 draft (10MB PDF), dated 2011-02-28 (prior to the release of the official C++11 standard), section 2.2:
翻译语法规则之间的优先级由以下阶段指定[见脚注].
The precedence among the syntax rules of translation is specified by the following phases [see footnote].
[footnote] 实现必须表现得好像这些单独的阶段发生一样,尽管在实践中不同的阶段可能会折叠在一起.
[footnote] Implementations must behave as if these separate phases occur, although in practice different phases might be folded together.
正如 [SNIP] 标记所示,我没有引用整个部分,只是足以让大家理解.
As indicated by the [SNIP] markers, I haven't quoted the entire section, just enough to get the idea across.
强调一下,编译器不需要遵循这个确切的模型,只要最终结果就像他们那样.
To emphasize, compilers are not required to follow this exact model, as long as the final result is as if they did.
阶段 1-6 或多或少对应于预处理器,7 阶段与您通常认为的编译相关,8 阶段处理模板,9 阶段对应链接.
Phases 1-6 correspond more or less to the preprocessor, 7 to what you might normally think of as compilation, 8 deals with templates, and 9 corresponds to linking.
(C 的翻译阶段类似,但省略了 #8.)
(C's translation phases are similar, but #8 is omitted.)
这篇关于C++程序的编译阶段有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!