Possible Duplicate:
How to understand complicated function declarations?
Consider:
char (*(*x())[5])()
How do I dissect this expression?
I think it is a function which return an array of size 5, whose members are pointers to function which receive no input and return a char.
Am I right?
The right-left rule [Important] This is a simple rule that allows you to interpret any declaration. It runs as follows: Start reading the declaration from the innermost parentheses, go right, and then go left.
int a[10]; refers to 10 cells of integers allocated in memory. int *b = a; is equivalent to int *b = &a[0]; and means that b points to the first cell of a to be precise.
Search for "Right-left rule"
In your case, it should be:
x : x is a
x() : function
*x() : returning pointer to
(*x())[5] : a 5-element array of
*(*x())[5] : pointer to
(*(*x())[5])() : function
char (*(*x())[5])() : returning char
I have been seeing a lot of weird declarations on Stack Overflow these days.
When I'm lazy, I use cdecl.org:
"declare x as function returning pointer to array 5 of pointer to function returning char"
When not, there is the clockwise spiral rule. <- It is AWESOME
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