Calling function pointed by void* pointer
You need to cast void*
pointer to the function pointer first:
#include <stdio.h>
typedef struct {
void* fn;
void* param;
} event;
void print()
{
printf("Hello\n");
}
int main()
{
event e;
e.fn = print;
((void(*)())e.fn)();
return 0;
}
Of course, if this is really what you want. If you want your struct to contain pointer to the function, instead of void*
pointer, use the proper type at the declaration:
typedef struct {
void (*fn)();
void* param;
} event;
Here you have fn
declared as a pointer to the void
function, and the param
as void*
pointer.