在语句中使用垃圾字符时没有编译器错误 #include
No compiler error on using garbage characters in #include statement
#include <iostream> gfhgfhgf
using namespace std;
int main() {
return 0;
}
为什么要编译此代码片段?根据 gcc 参考 包含语法:
如果文件名后面的行上有任何内容(注释除外),则为错误。
这正是代码中所做的。
在 gcc
中使用 -pedantic-errors
标志,clang
将其变成错误 实时查看:
error: extra tokens at end of #include directive
#include <iostream> gfhgfhgf
^
表示它是一个扩展。
如果我们看一下串联环境中的接口C和TAL,它们有一些这样的代码:
#include <stdlibh> nolist
^^^^^^
因此,gcc
和 clang
都支持在 include 指令后使用额外的字符,以支持某些平台上所需的扩展。使用 -pedantic 标志会gcc
,clang
为违反标准的扩展生成警告,如上所述,您可以使用-pendatic-errors
将其转换为错误(强调我的):
要获得标准要求的所有诊断,您应该 还要指定 -pedantic(或 -pedantic-errors ,如果你希望它们是 错误而不是警告)。
我们可以在 HP'sC/C++ 程序员指南中找到 nolist
NonStop 系统扩展的参考,其中说:
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++标准草案在第 16.2
节 [cpp.include] 中定义了这种include
形式的语法,如下所示:
# include < h-char-sequence> new-line
相关文章:
- C/C++编译器通常会删除重复的库吗
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- Win32编译器选项和内存分配
- 为什么 C++ 编译器在"c:program filesgnu emacsinclude"中查找包含文件?
- 使用许多嵌套的#include语句对编译器错误进行故障排除
- 如何向 g++ 编译器解释如何读取用于从'list'文件中搜索 .h 文件的'include'目录列表
- C++:为什么在 #include 之前调用 std::wstring::begin() 会导致<vector>此代码中的编译器错误?
- 哪些编译器可以使用 #include <thread> ,或者换句话说,支持也免费的C++ 11?
- 标准库编译器 来自 #include 的错误 -- 所有库都会导致终端错误
- 指示编译器忽略在#include中找到的标头前缀
- 不了解编译器如何搜索include
- 如何让 MS C++编译器识别 #include 中未定义的类型
- 在语句中使用垃圾字符时没有编译器错误 #include
- g++ #include 找不到文件编译器错误
- 使用 #include "filename" 时编译器错误
- 在用intel编译器编译代码时排除/usr/include/c++/4.3/
- 在源文件中指定include前缀与在编译器的搜索路径参数中指定include前缀的优缺点是什么
- 编译器会删除未使用的函数、定义、变量、宏、include等吗?
- visual studio-C++继承/#include(多个编译器错误)
- #include < WinUsb.h> 在 MFC 应用中产生编译器错误