首页> 智能网

函数指针编译时出错怎么办?

来源:智能网
时间:2021-06-16 19:47:59
热度:141

函数指针编译时出错怎么办?1. 问题粉丝提问:某个函数指针的使用:编译时出错了。type defaults to 'int' in declaration of 'on_touch

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 *);

首页 下一页 上一页 尾页
Baidu
map