#include“xxx.h”的规则是什么? Vs #include< xxx.h&gt ;? [英] What are the rules on #include "xxx.h" Vs #include <xxx.h>?

查看:217
本文介绍了#include“xxx.h”的规则是什么? Vs #include< xxx.h&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有我自己的库项目,我应该使用哪个样式 #include 他们在我的应用程序的头?有没有严格的规则,这两个实际上对编译器/预处理器有不同的意义,还是只有标准的?

解决方案

根据ISO标准,有很少的规则。这两种形式都是依赖于实现的,关于它们在哪里寻找头文件。他们甚至不必是文件。



部分 2.9 +11不区分这两个品种,除了您可以在<> 变体中包含> 变体,但很少有人会愚蠢地使用文件名中的这些字符: )



部分 16.2 进一步说明:







#include< h-char-sequence> new-line 搜索的预处理指令由< > 分隔符之间的指定序列唯一标识的头的一系列实现定义的位置,并且导致该指令被头部的整个内容替换。如何指定位置或识别的头是实现定义的。



预处理指令形式#includeq-char-sequencenew-line 导致由指定序列标识的源文件的全部内容替换该指令分隔符。以实现定义的方式搜索命名的源文件。如果不支持此搜索,或者搜索失败,则重新处理指令,如同它读取 #include < h-char-序列>





>

我倾向于使用<> 用于系统头文件和为我自己的标题,但这只是个人喜好。我注意到上述C ++ 11文档声明:


注意:虽然一个实现可能提供一种机制来使任意源文件可用到<> 搜索,一般程序员应该使用<>




实现和 p>这不是强制性的,但它是一个好主意。


If I have my own library projects, which style should I use to #include the headers from them in my application? Are there strict rules, and do the two actually have different meanings to the compiler/preprocessor or is it about standards only?

解决方案

There are few rules, according to the ISO standard. Both forms are implementation-dependent as to where they look for the header files. They don't even have to be files.

Section 2.9 of C++11 makes no distinction between the two varieties other than the fact you can include " in the <> variant and > in the "" variant but few people would be silly enough to use those characters in file names :-)

Section 16.2 further states:


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.


I tend to use <> for system headers and "" for my own headers, but that's personal preference only. I would note that the aforementioned C++11 document states:

Note: Although an implementation may provide a mechanism for making arbitrary source files available to the <> search, in general programmers should use the <> form for headers provided with the implementation, and the "" form for sources outside the control of the implementation.

This isn't mandated but it's a good idea nonetheless.

这篇关于#include“xxx.h”的规则是什么? Vs #include&lt; xxx.h&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆