Q
quark020
How to interpret this function pointer usage ?
int*(*q(char*))[];
TIA
int*(*q(char*))[];
TIA
How to interpret this function pointer usage ?
int*(*q(char*))[];
quark020 said:How to interpret this function pointer usage ?
int*(*q(char*))[];
quark020 said:How to interpret this function pointer usage ?
int*(*q(char*))[];
How to interpret this function pointer usage ?
int*(*q(char*))[];
TIA
How to interpret this function pointer usage ?int*(*q(char*))[];
TIA
The general procedure for reading hairy declarators is to find the
leftmost identifier and work your way out, remembering that absent any
explicit grouping with parentheses "[]" and "()" bind before "*", so
*a[] -- a is an array of pointer
(*a)[] -- a is a pointer to an array
*f() -- f is a function returning a pointer
(*f)() -- f is a pointer to a function
Sometimes in function parameter lists, you'll see things like "*[]" or
"(*)[]". These are interpreted the same way as above: "*[]"
designates an array of pointer, "(*)[]" designates a pointer to an
array, etc.
Thus, we parse your example as:
q -- q
q( ) -- is a function
q(char*) -- taking one pointer to char
*q(char*) -- returning a pointer
(*q(char*))[] -- to an array
*(*q(char*))[] -- of pointer
int *(*q(char*))[]; -- to int
cdecl's a wonderful tool, but this method's straightforward enough
that you shouldn't need it.
Ben Bacarisse said:quark020 said:How to interpret this function pointer usage ?
int*(*q(char*))[];
I've posted this before but not for a while so...
Put your finger on the name (or where the name would be) and read out
the name and the surrounding symbols using these rules:
* Always read to the left first but never past a ')'.
* Then read to the right.
* If you hit the start you are done.
* If you hit a '(' remove everything in the matching '(...)' pair
and start again reading to the left. [...snip...]
Tim Rentsch said:Ben Bacarisse said:quark020 said:How to interpret this function pointer usage ?
int*(*q(char*))[];
I've posted this before but not for a while so...
Put your finger on the name (or where the name would be) and read out
the name and the surrounding symbols using these rules:
* Always read to the left first but never past a ')'.
* Then read to the right.
* If you hit the start you are done.
* If you hit a '(' remove everything in the matching '(...)' pair
and start again reading to the left. [...snip...]
Presumably you mean right first, then left, then again to the
right...
Ha! Thanks for spotting that.
<aside>When giving directions in a car I have to hold the appropriate
hand out to indicate a direction....</aside>
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.