c语言中如何使用true和false

在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


这样你就明白了。