如何在C中引用深层嵌套的函数指针数组?

问题描述 投票:0回答:1

我基本上有这个:

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; } ...

c pointers function-pointers void-pointers jump-table
1个回答
0
投票

似乎您正在尝试制作一个函数指针数组。代码看起来像这样(部分代码):

© www.soinside.com 2019 - 2024. All rights reserved.