Rules for locating header files
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.
精彩评论