可能重复:
你如何阅读C声明?
我不明白以下几点:
int?? ?* (*(*p)[2][2])(int,int);
Run Code Online (Sandbox Code Playgroud)
你能帮我吗?
ism*_*ail 18
对于像这样的事情尝试cdecl,解码为;
declare p as pointer to array 2 of array 2 of pointer to function (int, int) returning pointer to int
Run Code Online (Sandbox Code Playgroud)
Joh*_*ode 16
p -- p
*p -- is a pointer
(*p)[2] -- to a 2-element array
(*p)[2][2] -- of 2-element arrays
*(*p)[2][2] -- of pointers
(*(*p)[2][2])( ); -- to functions
(*(*p)[2][2])(int,int); -- taking 2 int parameters
* (*(*p)[2][2])(int,int); -- and returning a pointer
int?? ?* (*(*p)[2][2])(int,int); -- to int
Run Code Online (Sandbox Code Playgroud)
这种野兽在实践中会是什么样子?
int *q(int x, int y) {...} // functions returning int *
int *r(int x, int y) {...}
int *s(int x, int y) {...}
int *t(int x, int y) {...}
...
int *(*fptr[2][2])(int,int) = {{p,q},{r,s}}; // 2x2 array of pointers to
// functions returning int *
...
int *(*(*p)[2][2])(int,int) = &fptr; // pointer to 2x2 array of pointers
// to functions returning int *
...
int *v0 = (*(*p)[0][0])(x,y); // calls q
int *v1 = (*(*p)[0][1])(x,y); // calls r
... // etc.
Run Code Online (Sandbox Code Playgroud)