Pointer to Function Pointer

会有一股神秘感。 提交于 2021-02-05 04:51:44

问题


Is it possible to create a pointer to a function pointer, i.e.

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

<unknown> = fp;

What needs to be written in place of unknown? With "normal" arrays, I could do this:

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

int* p = a;

Many thanks in advance.


回答1:


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



回答2:


typedef int32_t FP(void);

FP *fp[2] = { test_function1, test_function2 };
FP **p = fp;


来源:https://stackoverflow.com/questions/26013407/pointer-to-function-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!