函數指針編譯時出錯怎么辦?
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 *);

請輸入評論內容...
請輸入評論/評論長度6~500個字