假设我有a.h
其中包括以下内容:
<stdbool.h>
<stddef.h>
<stdin.h>
假设我还有b.h
其中还包括<stdbool.h>
。如果a.h
有#ifndef
其中的预处理器定义语句和 b.h
没有。会a.h
仅包含 b.h
中未包含的内容?那么当 b.h
包括a.h
,将 a.h
包括stddef.h
和stein.h
并且不重新包含stdbool.h
或者那些预处理器定义函数仅用于查看整个类是否被重新定义,而不是其中的特定函数?
编辑:
此外,假设 b.h
包含另一个头文件,其中包含 stdbool.h
-这使得b.h
有stdbool.h
都来自该类(class)和 a.h
。这会导致错误吗?
最佳答案
所有 C 标准头文件都必须能够以任意顺序多次包含:
Standard headers may be included in any order; each may be included more than once in a given scope, with no effect different from being included only once
关于c - 预处理器#ifndef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9690212/