gcc - 为什么要在项目中使用#include_next?

标签 gcc include c-preprocessor

引用iOS Documentation on Wrapper Headers :

#include_next does not distinguish between <file> and "file" inclusion, nor does it check that the file you specify has the same name as the current file. It simply looks for the file named, starting with the directory in the search path after the one where the current file was found.

The use of `#include_next' can lead to great confusion. We recommend it be used only when there is no other alternative. In particular, it should not be used in the headers belonging to a specific program; it should be used only to make global corrections along the lines of fixincludes.

那么,有两个问题,什么是#include_next,以及为什么需要使用它?

最佳答案

如果您想用您自己制作的 header 替换默认 header ,则可以使用它,例如,假设您想替换“stdlib.h”。您将在项目中创建一个名为 stdlib.h 的文件,该文件将代替默认 header 被包含在内。

如果您想向 stdlib.h 添加一些内容而不是完全替换它,则使用#include_next。您创建一个名为 stdlib.h 的新文件,其中包含:

#include_next "stdlib.h"
int mystdlibfunc();

并且编译器不会再次递归地包含您的 stdlib.h,就像普通的 #include 的情况一样,而是继续在其他目录中查找名为“stdlib.h”的文件。

关于gcc - 为什么要在项目中使用#include_next?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10261382/

相关文章:

c - 包含头文件时到底发生了什么?

c++ - #define 和预期的主表达式错误

c - 使用预处理器从 C 中的函数中获取 "remove"前缀

iphone - xcode 在模拟器和设备上安装速度很慢

c - 我是否误解了 GCC 中的 __attribute__ ((packed)) ?

macos - 如何在 macOS 10.13 上安装 gcc@7?

c++ - 如何指定远程预处理器包含路径,如 192.0.2.17 ://usr/include

c++ - 可以强制 GCC 为内存对齐对象生成有效的构造函数吗?

c++ - 在 .cpp 和 .h 中包含 header 的区别

c++ - Boost文档声明