我正在VS2013中编译以下代码,
#if (__STDC_VERSION__ >= 199901L)
/* Inactive pre-processor block */
#else
/* Active pre-processor block */
#ifndef __bool_true_false_are_defined
typedef unsigned char _Bool;
#define bool _Bool
#define false (0)
#define true (1)
#define __bool_true_false_are_defined (1)
#endif /* __bool_true_false_are_defined */
#endif
我的目标如下
- 如果编译器支持 C99,则不要创建
_Bool
类型,因为它已内置。 - 如果编译器不支持 C99,则创建自定义
_Bool
类型。
我的观察是代码进入了#else
block (不支持C99),但编译器仍然提示错误C2632:'char'后跟'bool'是非法的
以下是我对上述逻辑的一些疑问
- 预处理器检查 C99 支持是否正确?
- 如果 (1) 的答案是肯定的,那么为什么 C99 代码块在 VS2013 中不保持不活动状态。我假设 VS2013 有 C99 支持。
- 如果 VS2013 中没有 C99 支持,那么为什么编译器会提示
_Bool
的 typedef
最佳答案
看起来他们已经以另一种方式定义了它,_Bool
扩展为bool
。也许还可以用
#if defined(_Bool) || defined(bool)
..
#endif
关于c - 关于 _Bool 使用的 VS2013 编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22867695/