I am trying to create an array of pointers to functions, and trying to assign the function address to it. But i am getting errors which i dont know how to proceed with.
My code
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
But i am getting the following error
fsm.c:10: error: declaration 开发者_如何学JAVAof â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
Where am in going wrong
You are very close...
Try:
void (*Event_Handlers[3])();
For first time to be sure that you declared array of pointers to function use the following syntax:
typedef void (*func_t)();
func_t EventHandlers[3];
the array element type could be function pointer, but can not be function.
void (* Event_Handlers[3])()
will be the right answer
精彩评论