包括 C++ headers、“...”与 <...> 风格,官方 ISO/IEC 意见?

Including C++ headers, "..." vs. <...> style, official ISO/IEC opinion?

我知道,这是一个被问过很多次的老问题before。我同意 #include <filename> 应该用于系统 headers 并且 #include "filename" 应该用于 project-local headers.

的常见答案

但是,现在我发现 this paper 来自 ISO/IEC C++ 工具工作组,其中说明如下:

All headers within a project should be included using the <> style inclusion and contain the project name as a directory prefix. And all headers means all headers public, private, or implementation detail, in executables or in libraries.

他们也给出了解释:

The problem with the "" style inclusion is if the header is not found relative to the including file, most implementations will continue looking for it in the include search paths, the same as for <>. As a result, if the header is not present in the right place (for example, because it was mistakenly not listed as to be installed), chances are that a completely unrelated header with the same name will be found and included. Needless to say, debugging situations like these is unpleasant.

我不明白这个。为什么 <> 样式不会出现此问题?

奖金问题:无论如何,这样一篇论文的状态如何?它可以被视为 ISO/IEC C++ 联盟 peer-reviewed 的官方推荐并得到许多专家的认可吗?还是只是有人为了引发讨论而提出的建议?

我终于明白了。该论文的作者建议仅使用包含 -I 标志指定的编译器路径,但不要使用任何相对搜索路径。如果相对包含路径总是在 #include 语句中给出,并且只需要为项目的根目录提供一个 -I 标志,那么这是有意义的。

无论如何,这是一篇非常有趣的论文,它极大地改变了我对如何构造 C++ 组件的理解。我希望从委员会看到更多这样的东西。