C编译时`true'+undeclared+(first+use+in+this+function)

简介:

原文:http://liuzhigong.blog.163.com/blog/static/178272375201121664244437/


在编译C语言时有时会遇到这样的错误提示:
`true' undeclared (first use in this function) or `false' undeclared (first use in this function)
就是说 bool, true, false 都是undeclared,原因很简单,因为真正的C中没有这些关键字,c和早期的c++里没有关键字bool,使用BOOL可以,但BOOL不是内置类型了,都是通过typedef或者宏来定义的,通常都会被定义成int类型。后来的c++出现了内置类型bool,值只能为true(1)和false(0)。
解决方法:
1、将文件名.c改为文件名.cpp,用C++方式编译则没问题
2、自己进行一个宏定义:
 typedef enum __bool { false = 0, true = 1, } bool;
c90是没有bool的,因此支持c90的dev-c++当然也没有。想在c90里用bool,可以自行用宏进行定义。 
c99支持bool,用支持c99的编译器例如gcc就可以的。


相关文章
|
10月前
|
PHP
漏刻有时环境部署:php安装提示Can‘t use function return value in write context
漏刻有时环境部署:php安装提示Can‘t use function return value in write context
39 0
|
10月前
|
数据可视化 PHP
漏刻有时数据可视化大屏常见问题(1): Can’t use function return value in write context
漏刻有时数据可视化大屏常见问题(1): Can’t use function return value in write context
36 0
|
10月前
|
Linux
error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
80 0
|
Linux C++ Windows
error: ‘_beginthreadex‘ undeclared (first use in this function); did you mean ‘SDL_beginthread‘?
error: ‘_beginthreadex‘ undeclared (first use in this function); did you mean ‘SDL_beginthread‘?
519 0
error: ‘VPX_IMG_FMT_RGB32’ undeclared (first use in this function); did you mean ‘VPX_IMG_FMT_NV12’?
error: ‘VPX_IMG_FMT_RGB32’ undeclared (first use in this function); did you mean ‘VPX_IMG_FMT_NV12’?
85 0
|
Linux C++
O_RDONLY/O_NOATIME undeclared (first use in this function
O_RDONLY/O_NOATIME undeclared (first use in this function
138 0
O_RDONLY/O_NOATIME undeclared (first use in this function
error: x264_bit_depth undeclared (first use in this function) did you mean x264_picture_t
error: x264_bit_depth undeclared (first use in this function) did you mean x264_picture_t
129 0
|
11天前
|
JavaScript 前端开发
在JavaScript中,函数原型(Function Prototype)是一个特殊的对象
【5月更文挑战第11天】JavaScript中的函数原型是一个特殊对象,它为所有函数实例提供共享的方法和属性。每个函数在创建时都有一个`prototype`属性,指向原型对象。利用原型,我们可以向所有实例添加方法和属性,实现继承。例如,我们定义一个`Person`函数,向其原型添加`greet`方法,然后创建实例`john`和`jane`,它们都能调用这个方法。尽管可以直接在原型上添加方法,但推荐在构造函数内部定义以封装数据和逻辑。
21 2
|
11天前
|
存储 算法 对象存储
【C++入门到精通】function包装器 | bind() 函数 C++11 [ C++入门 ]
【C++入门到精通】function包装器 | bind() 函数 C++11 [ C++入门 ]
17 1
|
11天前
|
存储
function(函数)
在 Lua 中,函数作为第一类值可存储于变量,如示例所示:`factorial1` 和 `factorial2` 存储相同函数。此外,函数可作为参数传递,如 `testFun` 接收一个表和一个匿名函数,该匿名函数在迭代中处理键值对,输出 `key1=val1` 和 `key2=val2`。

热门文章

最新文章