我基本上有这个:
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]();
之类的操作会导致分割错误。>>
我基本上是这样的:void ** a; typedef void(* ExampleFn)(); void foo(){puts(“ hello”); } void init(){ExampleFn b [100] = {foo};一个= malloc(sizeof(void)* 10000); a [0] = b; } ...
似乎您正在尝试制作一个函数指针数组。代码看起来像这样(部分代码):