gpt4 book ai didi

c++ - 切勿使用 ' #include "filename.h"' 指令

转载 作者:搜寻专家 更新时间:2023-10-31 01:00:42 25 4
gpt4 key购买 nike

我对 [1] 中的“AV Rule 33”有疑问。

它说“#include 指令应使用 <filename.h> 符号来包含头文件。”。

该文档通过“供应商实现中的分歧”来“解释”它,但我很难相信它。 “本地头”文件是本地头文件?!

编译器在“本地”的定义上有那么大的不同吗?

[1] http://www.stroustrup.com/JSF-AV-rules.pdf

最佳答案

似乎是一个奇怪的理由。至少在 C 中,任何一种形式都是特定于实现的。

C11 6.10.2 和 C++03 16.2 在这里看起来 100% 相同:

A preprocessing directive of the form

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

searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.

A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

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

with the identical contained sequence (including > characters, if any) from the original directive.

正如我们在标准中所读到的,两种 形式都使用实现定义的搜索。标准明确声明如果#include "filename.h"失败,它将恢复为像 #include <filename.h>" 一样对待它.所以这个理由没有任何意义。

关于c++ - 切勿使用 ' #include "filename.h"' 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30474867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com