Rule for reading hairy ads: find the leftmost identifier and work outside, remembering that () and [] bind to * , so T *a[N] is an array of pointers to T , T (*a)[N] is equal to a pointer to an array from T , T *f() is a function that returns a pointer to T , and T (*f)() is a pointer to a function that returns T. Since a function prototype can omit parameter names, you can see things like T *[N] or T (*)() . The value is basically the same as 1, just pretending to have an identifier of length 0.
Thus,
p -- p p[3] -- is a 3-element array *p[3] -- of pointers (*p[3]) ( ) -- to functions (*p[3]) ( (*)()) -- taking a pointer to a function (*p[3]) ( * (*)()) -- returning a pointer (*p[3]) (void* (*)()) -- to void * (*p[3]) (void* (*)()) -- returning a pointer double* (*p[3]) (void* (*)()); -- to double
It is important to distract from the fact that you declare p as an array ... rather than returning a function ...
What would a beast look like in practice? Well, firstly, you will need three functions. Each of these functions takes one parameter, which is a pointer to a function that returns a pointer to void:
double *foo(void *(*)()); double *bar(void *(*)()); double *bletch(void *(*)()); double *(*p[3]) (void *(*)()) = {foo, bar, bletch};
Each of foo , bar and bletch will call the function passed to it and somehow return a pointer to double .
You would also like to define one or more functions that satisfy the type of parameters for each of foo , bar and bletch :
void *blurga() {...}
so if you call foo directly, you would name it as
double *pv; ... pv = foo(blurga);
So, we could imagine a challenge like
double *pv = (*p[0])(blurga);
1 - the difference lies in the fact that in the context of the declaration of the parameter of the function, T a[] and T a[N] identical to T *a ; in all three cases, a is a pointer to T , not an array of T Note that this is only true in the declaration of a function parameter. Thus, T *[] will be identical to T ** .John bode
source share