错误描述
unknown type name ‘bool’
最近使用C实现数据结构碰到了以下这个错误
➜ LinkedList gcc list.c
list.c:14:1: error: unknown type name ‘bool’; did you mean ‘_Bool’?
bool is_empty(PNODE pHead);
^~~~
_Bool
list.c:77:1: error: unknown type name ‘bool’; did you mean ‘_Bool’?
bool is_empty(PNODE pHead)
^~~~
_Bool
list.c: In function ‘is_empty’:
list.c:80:9: error: ‘true’ undeclared (first use in this function); did you mean ‘free’?
return true;
^~~~
free
list.c:80:9: note: each undeclared identifier is reported only once for each function it appears in
list.c:82:9: error: ‘false’ undeclared (first use in this function); did you mean ‘fclose’?
return false;
^~~~~
错误原因
未知的类型名:‘bool’, 因为在C语言标准(C89)没有定义布尔类型,所以会报错。而C99提供了一个头文件<stdbool.h>
定义了bool
,true
代表1,false
代表0。只要导入stdbool.h
,就能非常方便的操作布尔类型了。
解决方法
#include <stdbool.h>
参考链接
https://www.jianshu.com/p/aa951e784e96