A little fun with cdecl

Posted by Strainu on May 15, 2007
C

One of my teachers decided one day that he should write a pointer to an array of functions receiving a pointer to a function receiving an int and returning a pointer to a function receiving an array of pointers to int and returning int and an int and returning a pointer to a function receiving a pointer to a function receiving a pointer to an array of int and an int and returning a pointer to int and returning a function receiving int and returning int.

Fun, huh? :D Let’s try one more time:

a pointer to an array of functions
|  receiving a pointer to a function
|               |  receiving an int
|               |  returning a pointer to a function
|               |               |  receiving an array of pointer to int
|               |               |  returning int
|            an int
|  returning a pointer to a function
|               |  receiving a pointer to a function
|               |               |  receiving a pointer to an array of int
|               |               |            an int
|               |               |  returning a pointer to int
|               |  returning a function
|               |               |  receiving int
|               |               |  returning int

It does sounded quite tricky to me. Still, he managed to write it down in just 10 minutes. The secret? Cdecl. Cdecl reads files for statements which should be translated to C or C++. Six different statement are supported: declare composes a C type-declaration, cast composes a C type-cast, and so on. The grammar is described in full in the man page.

And here is the result for the function described above:

int ((*(*f)[] (int (*( * )(int))(int *[]), int))(int * ( * ) (int ( * )[], int)))(int)
Share and Enjoy:
  • Facebook
  • Twitter
  • Identi.ca
  • email
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Add to favorites

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>