gpt4 book ai didi

c - "nested"#includes 如何在 C 中工作?

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:05 25 4
gpt4 key购买 nike

假设有一个库/API 或一堆我想使用的代码(由其他人编写)并且它存储在任意文件夹中(例如 C:\randoAPIs\coolStuff\includes)。假设我的 main.c 位于不同的文件夹中,如 C:\MyCProjects\coolProject 并使用 coolStuff API,我将此包含路径添加到我的 IDE 并添加 #include "coolStuff.h";它工作正常。

问题是:

假设“coolStuff.h”本身包含一些其他头文件,如#include “boringStuff.h”; 编译器在哪里查找 boringStuff.h?在我的 main.c 文件夹中吗?或者在 coolStuff 的包含文件夹中?我的包含路径中的任何/所有文件夹? 或者这是一个特定于编译器的问题,我应该去阅读那个文档

最佳答案

它完全是实现定义的。 C11 6.10.2p3 :

3 A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

# include <h-char-sequence> new-line

with the identical contained sequence (including > characters, if any) from the original directive.

请注意 #include "coolStuff.h"不需要支持。另外#include "coolStuff.h"甚至可以映射到类似 #include <COOLSTUF.H> 的东西. C11 6.10.2p5 :

5 The implementation shall provide unique mappings for sequences consisting of one or more nondigits or digits (6.4.2.1) followed by a period (.) and a single nondigit. The first character shall not be a digit. The implementation may ignore distinctions of alphabetical case and restrict the mapping to eight significant characters before the period.

关于c - "nested"#includes 如何在 C 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45683019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com