I basically have some code that lets users register callbacks into a callback table at a specified index. There is one element in this table for each event that can trigger a callback. I basically do something like this:
In a header file
Code:
typedef struct _GMclient
{
GMcommunicator gcomm;
GMclient_callback callback_table[(int)MAX_CALLBACKS];
}GMclient;
typedef int (*GMclient_callback)(GMclient*, void*, void*);
Then I allow them to set the callback with a function that basically ends up doing this (in a .c file that includes the previous mentioned .h file):
Code:
void
GMclient_register_callback(GMclient *client,
GMclient_callback fxn,
int index)
{
assert (client);
assert (index < MAX_CALLBACKS);
client->callback_table[index] = fxn;
return;
}
Then later when I need to invoke that callback, I pull it out of the table
Code:
GMclient_callback *fxn = client->callback_table[CMD_INDEX];
However, I get compilation errors:
Code:
src/gmanager_client.c:43:6: error: a label can only be part of a statement and a declaration is not a statement
Any advice on what I'm doing wrong?