Pointer to an array of function pointers
int (*rdPtrList[4])(unsigned int addr, unsigned int data);
The above declares an array of size 4 of pointers for functions that returns an int and takes开发者_StackOverflow two unsigned int. I would like to make a pointer to this array. Is this possible in C?
Leaving out the parameters to keep the following easier to read:
p -- p *p -- is a pointer (*p)[4] -- to a 4-element array *(*p)[4] -- of pointers (*(*p)[4])() -- to functions int (*(*p)[4])(); -- returning int.
Ah, tricky tricky!!!
I think this works
int (*(*rdPtrList)[4])(unsigned int addr, unsigned int data);
because the compiler tells me _countof(*rdPtrList)
is 4.
(I wish you could just say int function(unsigned int addr, unsigned int data)[4]*
like you can in D, it's so much more readable: it would be a "function array pointer".)
Try this:
typedef int(*rdPtrList_t[4])(unsigned int addr, unsigned int data);
rdPtrList_t *ptrToArray;
精彩评论