Filename and line information
来自cppreference.com
< cpp | preprocessor
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
包括其他源文件后,立即指令到当前源文件的行.
原文:
Includes other source file into current source file at the line immediately after the directive .
目录 |
[编辑] 语法
#line lineno
|
(1) | ||||||||
#line lineno " filename"
|
(2) | ||||||||
[编辑] 解释
改变目前的预处理行号,lineno超越了这一点。展开的宏观__LINE__将扩大到lineno加上一些实际遇到的源代码行以来
2) 原文:
Changes the current preprocessor line number to lineno. Expansions of the macro __LINE__ beyond this point will expand to lineno plus the number of actual source code lines encountered since.
改变当前的预处理文件名filename的宏观扩张__FILE__从这个角度会产生filename
原文:
Also changes the current preprocessor file name to filename. Expansions of the macro __FILE__ from this point will produce filename.
任何预处理标记(宏常数或表达式)都可以作为参数
#line
,只要他们扩大到一个有效的十进制整数,可以有效的字符串原文:
Any preprocessing tokens (macro constants or expressions) are permitted as arguments to
#line
as long as they expand to a valid decimal integer optionally following a valid character string.[编辑] 注释
使用此指令在这种情况下,一些自动代码代工具它产生Ç+ +源文件从另一种语言编写的文件。
#line
指令插入在的产生Ç+ +文件引用的行数和在文件名的原(人可编辑)源文件原文:
This directive is used by some automatic code generation tools which produce C++ source files from a file written in another language. In that case,
#line
directives may be inserted in the generated C++ file referencing line numbers and the file name of the original (human-editable) source file.[编辑] 示例
#include <cassert> #define FNAME "test.cc" int main() { #line 777 FNAME assert(2+2 == 5); }
输出:
test: test.cc:777: int main(): Assertion `2+2 == 5' failed.