2

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.

5
  • 1
    try with spiral rule.. Commented Aug 9, 2013 at 11:45
  • Out of curiosity, where did you find this code? Looks like something from the IOCCC. Commented Aug 9, 2013 at 11:49
  • @sh1ftst0rm The linux kernel.. kidding :) It's from a really old code base at work. Commented Aug 9, 2013 at 11:53
  • 1
    cdecl.org is always nice for decoding stuff like this. Commented Aug 9, 2013 at 12:12
  • @JohnSmith sounds like your company used to have a Mel. =) Commented Aug 9, 2013 at 13:01

1 Answer 1

6

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. 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this is helpful - also @sujin's comment helped about the spiral rule. F is a pointer though and not a pointer (you forgot the () around f).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.