A little fun with cdecl

Posted by on mai 15, 2007
Fără categorie

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? 😀 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)

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Acest site folosește Akismet pentru a reduce spamul. Află cum sunt procesate datele comentariilor tale.