读书人

小弟我这样定义BOOL头文件可以吗

发布时间: 2013-08-10 21:14:06 作者: rapoo

我这样定义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


[解决办法]
引用:
谢谢大家,如果 我想在每个新建的文件或工程中都用到这个bool头文件,放在哪个地方可以每次写程序时只需要像调用stdio.h一样?而不需要每次都要把它先放到工程中。就像给没有行号的编译器增加行号一样,只需要增加某些东西一样,以后就可以直接用了?

放到include文件夹下吧,比如Linux /usr/include/
比如VC C:\Program Files\Microsoft Visual Studio\VC98\Include\

读书人网 >C语言

热点推荐