![](/img/trans.png)
[英]Declaration, allocation and assignment of an array of pointers to function pointers
[英]array of function declaration and assignment problem
我正在嘗試創建一個指向函數的指針數組,並嘗試將 function 地址分配給它。 但是我遇到了我不知道如何處理的錯誤。
我的代碼
void (*Event_Handlers)[3](); //Line no 10
/* Queue, Drop and Send_back have been defined. for eg */
void Queue()
{
....
}
Event_Handlers[0]=Queue; // Line 35
Event_Handlers[1]=Drop; // Line 36
Event_Handlers[2]=Send_Back; // Line 37
但我收到以下錯誤
fsm.c:10: error: declaration of âEvent_Handlersâ as array of functions
fsm.c:35: warning: data definition has no type or storage class
fsm.c:35: error: invalid initializer
fsm.c:36: warning: data definition has no type or storage class
fsm.c:36: error: invalid initializer
fsm.c:37: warning: data definition has no type or storage class
fsm.c:37: error: invalid initializer
哪里出了問題
你很親近...
嘗試:
void (*Event_Handlers[3])();
第一次確保您聲明指向 function 的指針數組使用以下語法:
typedef void (*func_t)();
func_t EventHandlers[3];
數組元素類型可以是 function 指針,但不能是 function。
無效 (* Event_Handlers[3])()
將是正確的答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.