开发者

Rules for locating header files

开发者 https://www.devze.com 2023-04-10 05:20 出处:网络
When you write #include \"foo.h\" I would expect the compiler to check the directory of the file doing the including (as opposed to the current directory) first, and if not found there then fall back

When you write #include "foo.h" I would expect the compiler to check the directory of the file doing the including (as opposed to the current directory) first, and if not found there then fall back on a search of the 开发者_StackOverflowlist of paths as in the case of #include <foo.h>.

Unless an absolute path was specified, #include "/foo.h", in which case only the absolute path needs to be checked.

Are there any C compilers where the rules are different?


Kernighan & Ritchie write:

[#include "foo"] searches first in association with the original source file (a deliberately implementation-dependent phrase), and if that search fails, then as in the first form.

Which means, make no assumption on the search strategy for quotes. However, all compilers I have run into share the praxis of searching in the including file's path first, and falling back to the compiler's search path if not found.

0

精彩评论

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