当你写 #include "foo.h"
我希望编译器首先检查执行包含(而不是当前目录)的文件的目录,如果没有找到,然后返回搜索路径列表,就像 #include <foo.h>
的情况一样。 .
除非指定绝对路径,#include "/foo.h"
, 在这种情况下只需要检查绝对路径。
有没有规则不同的 C 编译器?
最佳答案
Kernighan & Ritchie 写道:
[#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.
这意味着,不对报价的搜索策略做任何假设。但是,我遇到的所有编译器都共享首先在包含文件的路径中搜索的实践,如果找不到则回退到编译器的搜索路径。
关于c - 定位头文件的规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7645024/