c – 在#include语句中使用垃圾字符时无编译器错误

c – 在#include语句中使用垃圾字符时无编译器错误,第1张

概述#include <iostream> gfhgfhgfusing namespace std;int main() { return 0;} 为什么这段代码段编译?根据The gcc reference on Include Syntax: It is an error if there is anything (other than comments) on the line
#include <iostream> gfhgfhgfusing namespace std;int main() {    return 0;}

为什么这段代码段编译?根据The gcc reference on Include Syntax:

It is an error if there is anything (other than comments) on the line after the file name.

这正是代码中正在做的.

解决方法 使用gcc和clang中的-anticantic-errors标志将其转为错误 see it live:
error: extra tokens at end of #include directive#include <iostream> gfhgfhgf                    ^

这表明它是一个扩展.

如果我们看看Interfacing C and TAL In The Tandem Environment他们有一些这样的代码:

#include <stdlibh> noList                   ^^^^^^

所以gcc和clang都可以在include指令之后支持额外的字符,以支持某些平台上需要的扩展.使用-pedantic flags使gcc和clang对违反标准的扩展产生警告,如上所述,您可以使用-pendatic错误将其转换为错误(强调我的):

to obtain all the diagnostics required by the standard,you should
also specify -pedantic (or -pedantic-errors if you want them to be
errors rather than warnings).

我们可以在HP’sC/C++ Programmers guide for NonStop Systrms中找到诺尔扩展的参考,它说:

06002

注意,draft C++ standard在第16.2节[cpp.include]中定义了这种形式的包含的语法,如下所示:

# include < h-char-sequence> new-line
总结

以上是内存溢出为你收集整理的c – 在#include语句中使用垃圾字符时无编译器错误全部内容,希望文章能够帮你解决c – 在#include语句中使用垃圾字符时无编译器错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1254470.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存