C VS2013关于使用_Bool的编译问题
我正在VS2013中编译以下代码:C VS2013关于使用_Bool的编译问题,c,visual-studio,boolean,c99,C,Visual Studio,Boolean,C99,我正在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 (
#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,则不要创建
类型,因为它已内置\u Bool
- 如果编译器不支持C99,则创建一个自定义的
类型\u Bool
#else
块(不支持C99),但编译器仍然抱怨错误C2632:“char”后跟“bool”是非法的
以下是我对上述逻辑的几个问题
\u Bool
看起来他们已经用另一种方式定义了它,
\u Bool
扩展到Bool
。或者另外测试一下
#if defined(_Bool) || defined(bool)
..
#endif
我没有安装VS2013,但2012仍然支持C89(又名ansi C);我想2013年也是如此。你的代码为我编译。你能提供一个完整(但简短)的示例程序来演示你的错误吗?@BLUEPIXY,根据C2632,它表明
bool
已被设置为正确的类型(但不确定从哪个版本VS进行了更改)。这是否意味着VS2013中不支持C99,但有一些自定义设置可以为其创建适当的类型_Bool@simonc,我正在.c文件中添加代码。上面是我试图编译的所有测试代码片段。VS 2013包括_Bool。我的猜测是,他们可能没有撞上STDC_版本,因为支持不完整。