函数指针编译时出错怎么办?
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 *);
郑重声明:文章仅代表原作者观点,不代表本站立场;如有侵权、违规,可直接反馈本站,我们将会作修改或删除处理。
                        
                            相关阅读
                        
                        
                    
                            猜你喜欢
                        
                        -     
                                    详解Hive窗口函数实际应用2021-06-15
-     
                                    如何在动态链接库中调用外部函数?2021-05-24
-     
                                    如何在在动态链接库中调用外部函数?2021-05-24
-     
                                    如何运用StartupXLOG函数恢复读取WAL?2021-05-20

 
                                         
                                         
                                         
                                         
                                         2021-06-15
2021-06-15 
  
  
 
 新能源
新能源


