preprocessor的#ifndef [英] Preprocessor #ifndef
问题描述
假设我有 A.H
,其中包括以下内容:
Assume I have a.h
which includes the following:
<stdbool.h>
<stddef.h>
<stdin.h>
假设我也有 b.h
其中还包括&LT; stdbool.h&GT;
。如果啊
的的#ifndef
preprocessor定义语句在它和 BH
没有。将 A.H
只包括什么也没有被列入 b.h
?因此,当 BH
包括啊
,将啊
包括 STDDEF.H
和 stein.h
,而不是再包括 stdbool.h
或者是那些preprocessor定义功能仅用于看到全班同学是否进行了重新定义,而不是具体的职能范围内呢?
Assume I also have b.h
which also includes <stdbool.h>
. If a.h
has the #ifndef
preprocessor definition statement in it and b.h
doesn't. Will a.h
include only what hasn't been included in b.h
? So when b.h
includes a.h
, will a.h
include stddef.h
and stein.h
and not re-include stdbool.h
or are those preprocessor definition functions only used to see whether this whole class is redefined, and not specific functions within it?
编辑:
另外,假设 BH
包含另一个头文件,其中包括 stdbool.h
- 即品牌 BH
有 stdbool.h
无论从那个类和啊
。会导致错误的?
Also, assume b.h
includes another header file which includes stdbool.h
-that makes b.h
have stdbool.h
both from that class and a.h
. Will that cause errors?
推荐答案
所有的C头文件标准必须作出这样它们可以包含多次,以任意顺序:
All C standard headers must be made such that they can be included several times and in any order:
标准报头可以被包括在任何命令;每个可包括
作为多于在给定范围内一次,没有效果不同
包括只有一次
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
这篇关于preprocessor的#ifndef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!