John Smith
John Smith

Reputation: 25

Function pointer syntax in C

I'm learning C and in particular function pointers, I think I understand the basics.

However, this syntax baffles me, I'm not sure how to read this. I've run this through cdecl and tried reading it over and over but I'm not sure how to approach it.

char (* ( *f())[])();

I've tried compiling it and it works. I realize there is a pointer to a function here, and that it returns a function pointer itself - however, I don't know how to really read it. I went to open-std to check the specification but was unable to find the exact syntax for a function pointer to a function pointer.

If anyone could break this up for me - or tell me how I could break this up myself I would really appreciate it. Extra points for answers who explain how to approach these problems in the future. I tried searching for similar questions in Google and here but was unable to find anything this complicated.

Upvotes: 2

Views: 502

Answers (1)

P0W
P0W

Reputation: 47854

Well, following could help

f                     // identifier f
f()                   // is a function
*f()                  // that returns a pointer
(*f())[]              //  to an array
*(*f())[]             //  of pointers
(*(*f)[])()           // to functions 

char (* ( *f())[])(); // returning char. 

Upvotes: 6

Related Questions