u-boot中((void (*)(void)) addr) ();函數的用法

在bootwince.c中,do_bootwince{}函數最後調用了((void (*)(void)) addr) ();函數。

#include <stdio.h>
 
void sayhello(void)
{
        printf("hello godson!\n");
}
 
int main(void)
{
        /* normally, we use a function pointer such like this. */
        void (*p)(void);
        unsigned int addr;
 
        /* but we can use the address of a function directly. */
        addr = sayhello;
        printf("%d\n", addr);
        ((void (*)(void))addr)();
 
        /* use function pointer */
        p = sayhello;
        p();
 
        return 0;
}

子函數通過函數指針來調用函數。
發佈了45 篇原創文章 · 獲贊 6 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章