函數(shù)指針編譯時(shí)出錯(cuò)怎么辦?
1. 問題
粉絲提問:某個(gè)函數(shù)指針的使用:編譯時(shí)出錯(cuò)了。
type defaults to 'int' in declaration of 'on_touch_messgae_h(yuǎn)andle'[-Wimplicit-int] typedef(*on_touch_messgae_h(yuǎn)andle)(touch_message_t);
粉絲源碼如下:
2. 分析
1) 結(jié)構(gòu)解析
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_h(yuǎn)andle)(touch_message_t);
首先看下7行這個(gè)類型定義:
typedef struct touch_message * touch_message_t;
定義后
touch_message_t
等價(jià)于
struct touch_message *
就是說我們?nèi)绻胻ouch_message_t 定義的變量是一個(gè)struct touch_message類型的一個(gè)指針。
再來分析下8行這個(gè)定義:
typedef (*on_touch_messgae_h(yuǎn)andle)(touch_message_t);
可以替換成下面這個(gè)定義
typedef (*on_touch_messgae_h(yuǎn)andle)(struct touch_message *);

發(fā)表評論
請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個(gè)字
最新活動(dòng)更多
-
7月22-29日立即報(bào)名>> 【線下論壇】第三屆安富利汽車生態(tài)圈峰會(huì)
-
7.30-8.1火熱報(bào)名中>> 全數(shù)會(huì)2025(第六屆)機(jī)器人及智能工廠展
-
7月31日免費(fèi)預(yù)約>> OFweek 2025 具身機(jī)器人動(dòng)力電池技術(shù)應(yīng)用大會(huì)
-
免費(fèi)參會(huì)立即報(bào)名>> 7月30日- 8月1日 2025全數(shù)會(huì)工業(yè)芯片與傳感儀表展
-
即日-2025.8.1立即下載>> 《2024智能制造產(chǎn)業(yè)高端化、智能化、綠色化發(fā)展藍(lán)皮書》
-
8月5日立即報(bào)名>> 【在線會(huì)議】CAE優(yōu)化設(shè)計(jì):醫(yī)療器械設(shè)計(jì)的應(yīng)用案例與方案解析
推薦專題