訂閱
糾錯
加入自媒體

函數指針編譯時出錯怎么辦?

2021-06-16 15:41
一口Linux
關注

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

1  2  下一頁>  
聲明: 本文由入駐維科號的作者撰寫,觀點僅代表作者本人,不代表OFweek立場。如有侵權或其他問題,請聯(lián)系舉報。

發(fā)表評論

0條評論,0人參與

請輸入評論內容...

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

您提交的評論過于頻繁,請輸入驗證碼繼續(xù)

暫無評論

暫無評論

    掃碼關注公眾號
    OFweek人工智能網
    獲取更多精彩內容
    文章糾錯
    x
    *文字標題:
    *糾錯內容:
    聯(lián)系郵箱:
    *驗 證 碼:

    粵公網安備 44030502002758號