gcc编译报错unknown type name ‘bool‘

错误描述

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>定义了booltrue代表1,false代表0。只要导入stdbool.h,就能非常方便的操作布尔类型了。

解决方法

#include <stdbool.h>

参考链接

https://www.jianshu.com/p/aa951e784e96

  • 13
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值