我这样定义BOOL头文件可以吗?
C语言我的编译器中没有BOOL头文件,在网上看了一个头文件源码,有点不懂,自己简化一下,不知效果也网上是不是一样的?另外对网上的源码不懂的地方也想问一问。
我的写法是:
#ifndef STDBOOL_H_
#define STDBOOL_H_
#define bool _BOOL
#define true 1
#define false 0
#endif
网上的源码为:我的疑问用中文表达了,请帮忙解答一下。
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
/* Supporting <stdbool.h> in C++ is a GCC extension. */
#define _Bool //这里为什么后面没有接着赋值
#define bool bool //为什么是赋相同的值,下面两个同问。
#define false false
#define true true
#endif /* __cplusplus */
/* Signal that all the definitions are present. */
#define __bool_true_false_are_defined 1 //此处是什么意思?__bool_true_false_are_defined是什么意思?
#endif /* stdbool.h */
[解决办法]
编译选项加/EP /P,重新编译,查看宏展开后对应的.i文件。gcc加-E
[解决办法]
http://www.cplusplus.com/reference/cstdbool/
[解决办法]
typedef int BOOL;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
[解决办法]
放到include文件夹下吧,比如Linux /usr/include/
比如VC C:\Program Files\Microsoft Visual Studio\VC98\Include\