在被编译器错误指出之后,我注意到clang的stdbool.h
文件包括(其中包括)以下几行:
#define bool bool
#define false false
#define true true
它们包含在一个间接#ifdef
强制执行的块中__cplusplus
,因此,即使stdbool.h
是C标头,c ++标记也是如此。
这些定义有什么需要?我想出于某些与预处理器相关的原因而需要它们,但我想知道标准的哪一部分或哪个技术原因使之成为标准,因此clang必须包括这些内容。
stdbool.h
是一个C标头,而不是C ++标头。它通常在C ++程序中找不到,因为true
和false
在C ++中已经是关键字。
因此,如果包含C ++程序stdbool.h
,则很明显地表明它是移植的C程序(例如,被编译为C ++的C程序)。在这种情况下,stdbool.h
根据来自GCCstdbool.h
的注释,G ++在C ++模式下作为GNU扩展支持:
/* Supporting <stdbool.h> in C++ is a GCC extension. */
#define _Bool bool
#define bool bool
#define false false
#define true true
...
/* Signal that all the definitions are present. */
#define __bool_true_false_are_defined 1
同样,Clangstdbool.h
在C ++中支持与G ++的兼容性。在此故意定义这些值以匹配内置C ++类型,而不是传统的C99定义。它们被定义为宏,以提供与C99标准的某些兼容性,该标准要求:
标题应当载明下列宏:
bool
,true
,false
,__bool_true_false_are_defined
。应用程序可能会取消定义,然后可能会重新定义宏bool,true和false。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句