How to store various types of function pointers together?

前端 未结 4 570
滥情空心
滥情空心 2021-01-14 18:08

Normal pointers can be stored using a generic void*. e.g.

void* arr[10];
arr[0] = pChar;
arr[1] = pINt;
arr[2] = pA;

Sometime

4条回答
  •  感动是毒
    2021-01-14 19:00

    You can convert a function pointer to another function pointer of any function type and back without loss.

    So as long as when you make the call through the function pointer you typecast it back to the correct type first, you can store all of your function pointers in something like:

    typedef void (*fcn_ptr)(void);  // 'generic' function pointer
    
    fcn_ptr arr[10];
    

提交回复
热议问题