函数指针编译时出错怎么办?
1. 问题
粉丝提问:某个函数指针的使用:编译时出错了。
type defaults to 'int' in declaration of 'on_touch_messgae_handle'[-Wimplicit-int] typedef(*on_touch_messgae_handle)(touch_message_t);
粉丝源码如下:
2. 分析
1) 结构解析
1 struct touch_message
2 {
3 rt_uint16_t x;
4 rt_uint16_t y;
5 rt_uint8_t event;
6 };
7 typedef struct touch_message * touch_message_t;
8 typedef (*on_touch_messgae_handle)(touch_message_t);
首先看下7行这个类型定义:
typedef struct touch_message * touch_message_t;
定义后
touch_message_t
等价于
struct touch_message *
就是说我们如果用touch_message_t 定义的变量是一个struct touch_message类型的一个指针。
再来分析下8行这个定义:
typedef (*on_touch_messgae_handle)(touch_message_t);
可以替换成下面这个定义
typedef (*on_touch_messgae_handle)(struct touch_message *);

最新活动更多
-
3月27日立即报名>> 【工程师系列】汽车电子技术在线大会
-
4月30日立即下载>> 【村田汽车】汽车E/E架构革新中,新智能座舱挑战的解决方案
-
5月15-17日立即预约>> 【线下巡回】2025年STM32峰会
-
即日-5.15立即报名>>> 【在线会议】安森美Hyperlux™ ID系列引领iToF技术革新
-
5月15日立即下载>> 【白皮书】精确和高效地表征3000V/20A功率器件应用指南
-
5月16日立即参评 >> 【评选启动】维科杯·OFweek 2025(第十届)人工智能行业年度评选
发表评论
请输入评论内容...
请输入评论/评论长度6~500个字
暂无评论
暂无评论