函数指针编译时出错怎么办?
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 *);

最新活动更多
-
2月25日火热报名中>> Ansys Motion薄膜卷曲卷对卷工艺仿真解决方案
-
2月28日火热报名中>> 【免费试用】东集技术年终福利——免费试用活动
-
即日-3.21立即报名 >> 【深圳 IEAE】2025 消费新场景创新与实践论坛
-
3月27日立即报名>> 【工程师系列】汽车电子技术在线大会
-
4日10日立即报名>> OFweek 2025(第十四届)中国机器人产业大会
-
7.30-8.1火热报名中>> 全数会2025(第六届)机器人及智能工厂展
推荐专题
发表评论
请输入评论内容...
请输入评论/评论长度6~500个字
暂无评论
暂无评论