我基本上有这个:
void **a;
typedef void (*ExampleFn)();
void
foo() {
puts("hello");
}
void
init() {
ExampleFn b[100] = {
foo
};
a = malloc(sizeof(void) * 10000);
a[0] = b;
}
int
main() {
init();
ExampleFn x = a[0][0];
x();
}
但是在运行时,我会遇到各种错误,例如:
error: subscript of pointer to function type 'void ()'
我怎样才能让它工作?
做类似的事情((ExampleFn*)a[0])[0]();
会导致分段错误。