#include 指令:“test.h”与“test.h”之间的区别和“./test.h”
对于 C/C++ 预处理器,#include "./test.h"
和 #include "test.h"
之间有什么区别吗?
Is there any difference between #include "./test.h"
and #include "test.h"
for the C/C++ preprocessor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,没有区别。
你也可以有
它会是一样的
No, there is no difference.
You could also have
And it would be the same
根据 C 标准,没有区别:编译器可以指定如何搜索它们。实际上,对于我所知道的任何实现来说,也不应该有任何差异。
According to the C standard, there is no difference: the compiler gets to specify how they are searched. In practice, there shouldn't be any difference, either, for any of the implementations I am aware of.
预处理器将同等对待这两种样式。标准做法是
将包含文件路径作为选项传递给编译器。 (例如,GCC 的 -I 选项)。这使得更改头文件的位置变得容易。您只需在项目的 make 文件中进行一次更改即可。
Both styles will be treated the same by the pre-processor. The standard practice is
and pass the include file path as an option to the compiler. (For instance, the -I option of GCC). This makes it easy to change the location of header files. You just need to make a single change in the project's make file.
我认为有一个重要的区别。
对于
#include "test.h"
,将在使用选项 -I 为编译器指定的所有目录中搜索包含文件。在
#include "./test.h"
的情况下,仅使用引用文件的驻留目录。In my opinion there is an important difference.
In the case of
#include "test.h"
the include file is searched for in all directories specified to the compiler with the option -I.In the case of
#include "./test.h"
only the residing directory of the referring file is used.