quark020
2/10/2011 5:15:00 AM
On Feb 9, 8:11 pm, John Bode <jfbode1...@gmail.com> wrote:
> On Feb 9, 6:15 am, quark020 <quark...@gmail.com> wrote:
>
> > 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.
Thanks a lot.. :-)