在LLVM项目的源代码中stdbool.h
,其内容为:
/* Don't define bool, true, and false in C++, except as a GNU extension. */
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool, bool, false, true as a GNU extension. */
#define _Bool bool
#define bool bool
#define false false
#define true true
#endif
在最后4行中,有from的3行#define X X
。为什么要这么做?有什么区别?这是不是力编译器只需更换,也就是说,true
用true
?
我能想到的唯一原因是,这样的预处理程序语句
#ifdef bool
// do some stuff or define bool
#endif
在其他C文件中,之后将正常工作,并且不尝试以其他方式重新定义bool
#define bool int
这会干扰第一个定义
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句