#include <iostream> gfhgfhgf
using namespace std;
int main() {
return 0;
}
为什么这段代码可以编译?按照有关包含语法的 gcc 参考:
如果文件名后面的行中有任何内容(注释除外),则表示错误。
这正是代码中所做的事情。
使用-pedantic-errors
标志在gcc
and clang
将其变成错误现场观看:
error: extra tokens at end of #include directive
#include <iostream> gfhgfhgf
^
这表明它是一个扩展。
如果我们看一下在串联环境中连接 C 和 TAL他们有一些这样的代码:
#include <stdlibh> nolist
^^^^^^
So both gcc
and clang
支持 include 指令后的额外字符,以支持某些平台上所需的扩展。使用-迂腐的旗帜 makes gcc
and clang
对违反标准的扩展产生警告,如上所述,您可以使用-pendatic-errors
将其变成错误(强调我的):
to 获得标准所需的所有诊断, 你应该
还指定 -pedantic (或 -pedantic-errors 如果您希望它们是
错误而不是警告)。
我们可以找到一个参考nolist
扩展在HPsC/C++ 不间断系统程序员指南其中说:
nolist
directs the compiler not to list the contents of the file or sections
being included.
This is an HP NonStop extension to the standard.
注意,C++ 标准草案定义了这种形式的语法include
在部分16.2
[cpp.include]如下:
# include < h-char-sequence> new-line
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)