(C,C++)翻译的阶段(Phases of Translation)[SH]

silentmj@126翻译,出自MSDN2001->Visual C++ Programmer's Guide->Preprocessor Reference->The Preprocessor->Phases of Translation
觉得准确翻译是件困难的事情,欢迎指正.
{...}中的内容是我觉得拿不准或者比较重要的概念,认为标注出原文有助于理解原文意思.
带下划线的内容表示觉得原文有误或者我还不理解的句子
-----------------这,是一个分隔符------------------
纯译文
翻译的阶段
C 和 C++ 程序包含一个或多个源文件, 每一个都包含程序的一些文本{text}.一个源文件, 和它所包含的文件(即使用#include指令包含的文件),但是不和被条件编译指令如#if等去除掉的代码段一起被称作一个translation unit.
源文件可以在不同的时候被翻译.事实上,只翻译过时的文件是很常见的.多个被翻译过的翻译单位可以被保存在分离的目标代码文件或者目标代码库中.这些分离的翻译单位将在以后被连接以形成一个可执行程序或者动态连接库(DLL).
Translation unit之间可以发生联系{communicate}通过:


  • 调用具有外部连接属性的函数.
  • 调用类中具有外部连接属性的成员函数.
  • 直接改变具有外部连接属性的对象.
  • 直接改变文件.
  • 进程间通信(只适用于基于微软Windows操作系统的程序).

下面的列表描述了编译器翻译文件的各个阶段:
字符映射
源文件中的字符被映射到内部表示形式.在这个阶段中,三元组被转化为单字符的内部表示形式
行分割
源文件中所有以反斜线(/)结尾并紧跟一个新行字符{newline character}结尾的行被和下一行连结,这便使得物理行形成了逻辑行.除非文件是空的,一个源文件必须以前面不接反斜线的新行字符结尾.
符号化
源文件被分解为预处理符号和空白字符.源文件中的每个注释被替换为一个空格.换行符被保留.
预处理
预处理指令被执行并且宏被展开到源文件中.#include语句调用以之前的三个翻译步骤于任何被包含的文本.
字符集映射
所有的源字符集和换码序列{escape sequences}被转换为他们在执行字符集中的等价符号.对于微软C和C++, 源和执行字符集都是ASCII
字符串连结
所有邻接的(字符)串和宽(字符)串中的文字(literal)被连结起来.例如, "String " "concatenation" 变为"String concatenation".
翻译
所有的符号{token}在句法和语意上被分析.这些符号被转变为目标代码{object code}
连接
所有的外部引用均被解析以创建可执行程序或者动态连接库.

在遇到句法错误的阶段阶段中,编译器会发出警告或者错误.

连接器解析所有的外部引用并通过将一个或多个单独处理的翻译单元(translation unit)与标准库合并以创建可执行程序或者动态连接库.

对照译文
Phases of Translation
翻译的阶段
C and C++ programs consist of one or more source files, each of which contains some of the text of the program. A source file, together with its include files (files that are included using the #include preprocessor directive) but not including sections of code removed by conditional-compilation directives such as #if, is called a “translation unit.”
C 和 C++ 程序包含一个或多个源文件, 每一个都包含程序的一些文本{text}.一个源文件, 和它所包含的文件(即使用#include指令包含的文件),但是不和被条件编译指令如#if等去除掉的代码段一起被称作一个translation unit.
Source files can be translated at different times — in fact, it is common to translate only out-of-date files. The translated translation units can be kept either in separate object files or in object-code libraries. These separate translation units are then linked to form an executable program or a dynamic-link library (DLL).
源文件可以在不同的时候被翻译.事实上,只翻译过时的文件是很常见的.多个被翻译过的翻译单位可以被保存在分离的目标代码文件或者目标代码库中.这些分离的翻译单位将在以后被连接以形成一个可执行程序或者动态连接库(DLL).

Translation units can communicate using:
Translation unit之间可以发生联系{communicate}通过:


  • Calls to functions that have external linkage.
    调用具有外部连接属性的函数.
  • Calls to class member functions that have external linkage.
    调用类中具有外部连接属性的成员函数.
  • Direct modification of objects that have external linkage.
    直接改变具有外部连接属性的对象.
  • Direct modification of files.
    直接改变文件.
    Interprocess communication (for Microsoft Windows-based applications only).
  • 进程间通信(只适用于基于微软Windows操作系统的程序).
  1.  


The following list describes the phases in which the compiler translates files:
下面的列表描述了编译器翻译文件的各个阶段:
Character mapping
字符映射
Characters in the source file are mapped to the internal source representation. Trigraph sequences are converted to single-character internal representation in this phase.
源文件中的字符被映射到内部表示形式.在这个阶段中,三元组被转化为单字符的内部表示形式

Line splicing
行分割
All lines ending in a backslash (/) and immediately followed by a newline character are joined with the next line in the source file, forming logical lines from the physical lines. Unless it is empty, a source file must end in a newline character that is not preceded by a backslash.
源文件中所有以反斜线(/)结尾并紧跟一个新行字符{newline character}结尾的行被和下一行连结,这便使得物理行形成了逻辑行.除非文件是空的,一个源文件必须以前面不接反斜线的新行字符结尾.

Tokenization
符号化
The source file is broken into preprocessing tokens and white-space characters. Comments in the source file are replaced with one space character each. Newline characters are retained.
源文件被分解为预处理符号和空白字符.源文件中的每个注释被替换为一个空格.换行符被保留.

Preprocessing
预处理
Preprocessing directives are executed and macros are expanded into the source file. The #include statement invokes translation starting with the preceding three translation steps on any included text.
预处理指令被执行并且宏被展开到源文件中.#include语句调用以之前的三个翻译步骤于任何被包含的文本.

Character-set mapping
字符集映射
All source-character-set members and escape sequences are converted to their equivalents in the execution-character set. For Microsoft C and C++, both the source and the execution character sets are ASCII.
所有的源字符集和换码序列{escape sequences}被转换为他们在执行字符集中的等价符号.对于微软C和C++, 源和执行字符集都是ASCII

String concatenation
字符串连结
All adjacent string and wide-string literals are concatenated. For example, "String " "concatenation" becomes "String concatenation".
所有邻接的(字符)串和宽(字符)串中的文字(literal)被连结起来.例如, "String " "concatenation" 变为"String concatenation".
Translation
翻译
All tokens are analyzed syntactically and semantically; these tokens are converted into object code.
所有的符号{token}在句法和语意上被分析.这些符号被转变为目标代码{object code}
Linkage
连接
All external references are resolved to create an executable program or a dynamic-link library.
所有的外部引用均被解析以创建可执行程序或者动态连接库.

The compiler issues warnings or errors during phases of translation in which it encounters syntax errors.
在遇到句法错误的阶段阶段中,编译器会发出警告或者错误.

The linker resolves all external references and creates an executable program or DLL by combining one or more separately processed translation units along with standard libraries.
连接器解析所有的外部引用并通过将一个或多个单独处理的翻译单元(translation unit)与标准库合并以创建可执行程序或者动态连接库.

原文

QUOTE:

Phases of Translation
C and C++ programs consist of one or more source files, each of which contains some of the text of the program. A source file, together with its include files (files that are included using the #include preprocessor directive) but not including sections of code removed by conditional-compilation directives such as #if, is called a “translation unit.”
Source files can be translated at different times — in fact, it is common to translate only out-of-date files. The translated translation units can be kept either in separate object files or in object-code libraries. These separate translation units are then linked to form an executable program or a dynamic-link library (DLL).
Translation units can communicate using:



  • Calls to functions that have external linkage.
  • Calls to class member functions that have external linkage.
  • Direct modification of objects that have external linkage.
  • Direct modification of files.
  • Interprocess communication (for Microsoft Windows-based applications only).
  1.  
The following list describes the phases in which the compiler translates files:
Character mapping
Characters in the source file are mapped to the internal source representation. Trigraph sequences are converted to single-character internal representation in this phase.
Line splicing
All lines ending in a backslash ( /) and immediately followed by a newline character are joined with the next line in the source file, forming logical lines from the physical lines. Unless it is empty, a source file must end in a newline character that is not preceded by a backslash.
Tokenization
The source file is broken into preprocessing tokens and white-space characters. Comments in the source file are replaced with one space character each. Newline characters are retained.
Preprocessing
Preprocessing directives are executed and macros are expanded into the source file. The #include statement invokes translation starting with the preceding three translation steps on any included text.
Character-set mapping
All source-character-set members and escape sequences are converted to their equivalents in the execution-character set. For Microsoft C and C++, both the source and the execution character sets are ASCII.
String concatenation
All adjacent string and wide-string literals are concatenated. For example, "String " "concatenation" becomes "String concatenation".
Translation
All tokens are analyzed syntactically and semantically; these tokens are converted into object code.
Linkage
All external references are resolved to create an executable program or a dynamic-link library.
The compiler issues warnings or errors during phases of translation in which it encounters syntax errors.
The linker resolves all external references and creates an executable program or DLL by combining one or more separately processed translation units along with standard libraries.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值