我在這里新了解了函式指標 ,但我無法定義指向 be32toh() 或其他endian.hheader函式的函式指標。
首先,我可以按照給定執行緒中的說明執行操作:
#include <endian.h>
int addInt(int n, int m) {
return n m;
}
int main(){
int (*functionPtr)(int,int);
functionPtr = addInt;
return 0;
}
但是,當我嘗試對類似 的函式執行相同操作時be32toh(),會出現編譯錯誤:
#include <stdint.h>
#include <endian.h>
int addInt(int n, int m) {
return n m;
}
int main(){
int (*functionPtr)(int,int);
functionPtr = addInt;
uint32_t (*newptr)(uint32_t);
newptr = &be32toh;
return 0;
}
編譯為:
$ gcc test.c
結果如下:
test.c: In function ‘main’:
test.c:15:15: error: ‘be32toh’ undeclared (first use in this function)
15 | newptr = &be32toh;
| ^~~~~~~
test.c:15:15: note: each undeclared identifier is reported only once for each function it appears in
有什么問題以及如何解決?
uj5u.com熱心網友回復:
有什么問題
be32toh 是一個宏。
如何解決?
自己寫函式就行了。
uint32_t be32toh_func(uint32_t a) {
return be32toh(a);
}
....
newptr = &be32toh_func;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/364670.html
上一篇:將變數恢復為其原始值
