Sri Harsha Dandibhotla said:
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn't make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.
Start with x, the identifier.
Look immediately right. Is it a [ ? No.
Is it a (? Yes: x( Keep reading until you hit the closing parenthesis.
char(*(* )[ ])()
x()
"x is a function returning"
Now read left. Is it a ( ? No.
Is it a *, const, or volatile? If so, keep reading left till it isn't:
char(*( )[ ])()
*x()
"x is a function returning a pointer to"
Is the next thing on the left a (? Yes, and this is a grouping thing, so we
can just balance out parentheses, without adding anything:
char(* [ ])()
(*x())
"x is a function returning a pointer to"
Look right. Is the thing on the right a [? Yes, it is.
char(* )()
(*x())[ ]
"x is a function returning a pointer to an array of"
Is the thing to the right a (? No.
Is the thing to the left a (? No.
Is the thing to the left a const, volatile, or *? Yes. Keep reading left until
it isn't.
char( )()
*(*x())[ ]
"x is a function returning a pointer to an array of pointer to"
Is the thing to the left a (? Yes. Read up to the ).
char ()
(*(*x())[ ])
"x is a function returning a pointer to an array of pointer to"
Is the thing to the right a [ ? No.
Is the thing to the right a (? Yes. Read up to the matching )...
char
(*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning"
Is the thing to the left a (? No.
Is it const/volatile/*? No.
Whatever's left, tack on the end:
char (*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning char"
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999