开发者

#include directive: difference between "test.h" and "./test.h"

开发者 https://www.devze.com 2022-12-08 23:30 出处:网络
Is there any difference between #include \"./test.h\" and #i开发者_JAVA百科nclude \"test.h\" for the C/C++ preprocessor?No, there is no difference.

Is there any difference between #include "./test.h" and #i开发者_JAVA百科nclude "test.h" for the C/C++ preprocessor?


No, there is no difference.

You could also have

#include "../thisdir/test.h"

And it would be the same


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.


Both styles will be treated the same by the pre-processor. The standard practice is

#include "test.h"

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消