函数指针定义的一个错误

资讯 3年前
789

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

© 版权声明

相关文章