How do I understand following complicated declarations?
char (*(*f())[])(); char (*(*X[3])())[5]; void (*f)(int,void (*)()); char far *far *ptr; typedef void (*pfun)(int,float); int **(*f)(int**,int**(*)(int **,int **));
Complicated declarations in C. Redeclaration of global variable in C. Internal Linkage and External Linkage in C. Different ways to declare variable as constant in C and C++ Variable length arguments for Macros.
A function with same name cannot have different return types. A function with same name cannot have different number of parameters. A function with same name cannot have different signatures.
As others have pointed out, cdecl is the right tool for the job.
If you want to understand that kind of declaration without help from cdecl, try reading from the inside out and right to left
Taking one random example from your list char (*(*X[3])())[5];
Start at X, which is the identifier being declared/defined (and the innermost identifier):
char (*(*X[3])())[5]; ^
X is
X[3] ^^^
X is an array of 3
(*X[3]) ^ /* the parenthesis group the sub-expression */
X is an array of 3 pointers to
(*X[3])() ^^
X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments
(*(*X[3])()) ^ /* more grouping parenthesis */
X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments and returning a pointer
(*(*X[3])())[5] ^^^
X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments and returning a pointer to an array of 5
char (*(*X[3])())[5]; ^^^^ ^
X is an array of 3 pointers to function accepting an unspecified (but fixed) number of arguments and returning a pointer to an array of 5 char.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With