c语言中如何使用bool true false

来源:互联网 发布:淘宝联盟验证失败 编辑:程序博客网 时间:2024/05/23 19:16

在C99之前,我想很多人都是自己定义bool true false,

比如typedef int bool或者#define bool int

#define true 1

#define false 0

在C99出来后,没必要这样做了,

C99定义了一个_Bool的类型,

你可能会问了,为啥不是bool,如果想用bool的话,也可以,C99提供了头文件stdbool.h,包含即可,

我们可以看下stdbool.h里怎么写的,

#ifndef _STDBOOL_H#define _STDBOOL_H#ifndef __cplusplus#define bool    _Bool#define true    1#define false   0#else /* __cplusplus */...#endif...#endif

这样你就明白了。

原创粉丝点击