blog.TangGaowei.com

关于Linux下C语言编译器gcc不认识bool类型的问题

作者 Neot 写于 2006-07-18  | 431 次浏览

  这几天在学习Linux下的C语言开发。今天要写一个取1到100之间质数的题。可是,当我用bool类型定义变量b,来标记一个数是否为质数时,编译出错。错误信息显示如下:

‘bool’ undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)

在Google在搜了半天,也没不明白。后来,只得请求高手。得到回复,总结于下:

C语言(或C++)里本身没有bool这种布尔类型。有些编译器可以识别,那也是因为编译器自己定义了bool类型,比如:#define bool int。

C语言里,一般用整型变量来实现布尔型变量的功能。当用条件语句,如if,进行判断时,值为0时返回false,其它都返回true。

[ 标签: c++, linux, 数据类型 ]
[ 固定链接:http://blog.tanggaowei.com/2006/07/linuxcgccbool.html ]

订阅

 

手机访问

http://blog.tanggaowei.com/wap/

Google