訂閱
糾錯(cuò)
加入自媒體

函數(shù)指針編譯時(shí)出錯(cuò)怎么辦?

1. 問(wèn)題

粉絲提問(wèn):某個(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 *

就是說(shuō)我們?nèi)绻胻ouch_message_t 定義的變量是一個(gè)struct touch_message類型的一個(gè)指針。

再來(lái)分析下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 *);

1  2  下一頁(yè)>  
聲明: 本文由入駐維科號(hào)的作者撰寫(xiě),觀點(diǎn)僅代表作者本人,不代表OFweek立場(chǎng)。如有侵權(quán)或其他問(wèn)題,請(qǐng)聯(lián)系舉報(bào)。

發(fā)表評(píng)論

0條評(píng)論,0人參與

請(qǐng)輸入評(píng)論內(nèi)容...

請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字

您提交的評(píng)論過(guò)于頻繁,請(qǐng)輸入驗(yàn)證碼繼續(xù)

  • 看不清,點(diǎn)擊換一張  刷新

暫無(wú)評(píng)論

暫無(wú)評(píng)論

人工智能 獵頭職位 更多
掃碼關(guān)注公眾號(hào)
OFweek人工智能網(wǎng)
獲取更多精彩內(nèi)容
文章糾錯(cuò)
x
*文字標(biāo)題:
*糾錯(cuò)內(nèi)容:
聯(lián)系郵箱:
*驗(yàn) 證 碼:

粵公網(wǎng)安備 44030502002758號(hào)