Cdecl – Turns English phrases into C declarations
Here&#x27;s an easy way to understand how these things work: in C, the type of a pointer&#x2F;function&#x2F;array mess is declared by how it&#x27;s used. For a declaration like &quot;int ( * ( * foo)(void))[3]&quot;, you can read it as &quot;for a variable foo, after computing the expression ( * ( * foo)(void))[3], the result is an int.&quot;<p>So one way to read C &quot;gibberish&quot; is to ignore the type at the beginning and parse the rest as an expression like a normal parse tree. First we take foo. Then we dereference it (so foo is a pointer). Next we call it as a function with no arguments (so foo is a pointer to a function that takes no arguments). Next, we dereference it again. Then we index into the result as an array. Finally, we reach the end, so we look at what the declared type and find that this type is an int. So foo is a pointer to a function that takes no arguments and returns a pointer to an array of 3 ints.<p>You can also use this to go backwards. What&#x27;s the syntax for a function that takes an integer argument returns a pointer to an array of function pointers taking no arguments and returning integers? Well, we want to take foo, call it, dereference it, then index into an array, then dereference it again, then call it again, then return an int. Or int (* (* (foo)(int))[5])(void).