c - 指向函数指针的指针

标签 c pointers function-pointers

是否可以创建指向函数指针的指针,即

int32_t (*fp[2])(void) = {test_function1, test_function_2}; // initialize a function pointer

<unknown> = fp;

需要写什么来代替未知?使用“普通”数组,我可以这样做:

int a[2] = {0, 1};

int* p = a;

非常感谢。

最佳答案

typedef void(*func_ptr_t)(void); // a function pointer

func_ptr_t* ptr_to_func_ptr;     // a pointer to a function pointer - easy to read
func_ptr_t  arr[2];              // an array of function pointers - easy to read

void(**func_ptr_ptr)(void);      // a pointer to a function pointer - hard to read
void(*func_ptr_arr [2])(void);   // an array of function pointers - hard to read

关于c - 指向函数指针的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26013407/

相关文章:

c - APU 上的 OpenCL 是否能够使用整个内存?

c++ - 拥有对象实例与拥有指针

c - 这 5 种无数种声明/初始化常量限定指针的方法有什么问题?(摘自一本可疑但受欢迎的书)

c++ - 如何在 C++ 中获取指向 main() 方法的函数指针?

c - 保证指向标准函数的指针不相等?

java - C服务器和java客户端

c - format ‘%f’ 需要类型为 ‘float *’ 的参数,但参数 2 的类型为 ‘double *’ [-Wformat=] scanf ("%1f", &n);

c - 使用 libcurl 使 https get

c - 是(char *)NULL-(char *)NULL未定义行为吗?

c++ - 有什么方法可以通过在 C++ 中读取文件来构造函数指针