C中的所有版本,将有效地治疗以外的任何整数值0作为true比较运营商和整数值0的false。如果您没有C99_Bool或bool从C99开始可用,则可以使用#define宏在C中模拟布尔数据类型,并且您仍然可能会在旧版代码中找到这种情况。
#include <stdio.h>
#define bool int
#define true 1
#define false 0
int main(void) {
bool x = true; /* Equivalent to int x = 1; */
bool y = false; /* Equivalent to int y = 0; */
if (x) /* Functionally equivalent to if (x != 0) or if (x != false) */
{
puts("这将打印!");
}
if (!y) /* Functionally equivalent to if (y == 0) or if (y == false) */
{
puts("这也将打印!");
}
}请勿在新代码中引入此内容,因为这些宏的定义可能与的现代用法冲突<stdbool.h>。