ESP32报错处理

本文详细解析了C++编程中常见的警告类型,包括const指针警告、函数参数类型不匹配警告以及未使用变量警告。针对这些问题,提出了明确的解决方法,如正确使用const关键字,调整函数参数类型,以及避免定义未使用的变量,帮助程序员提高代码质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
原因:把const修饰的类型的地址赋值给了别人
解决方法:把被复制的类型加上const修饰,或者把被const修饰的类型的地址强制类型转换
例子:
const int a = 9; int *pa = &a;就会报这个警告!
方法一:const int *pa = &a;
方法二:int *pa = (int *)&a; 这种方法改变了const的“常量特性”

2.warning: passing argument 1 of ‘prtclFile_convertTo_profileValue’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
原因:函数的第1个输入参数’prtclFile_convertTo_profileValue’,把const修饰的类型作为非const类型使用(比如作为函数输入参数)
解决方法:修改函数的入口参数类型为const or 用的时候强制类型转换把const特性去掉

3.warning: passing argument 3 of ‘prtclFile_convertTo_profileValue’ from incompatible pointer type [-Wincompatible-pointer-types]
原因:函数的第3个输入参数’prtclFile_convertTo_profileValue’ ,忽视指针类型不对的问题
解决方法:修改函数的入口参数类型or用的时候强制类型转换

4.warning: variable ‘pObject’ set but not used [-Wunused-but-set-variable]
原因:变量’pObject’初始化了,但是没用到
结局方法:去掉这个变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值