Here's an easy way to understand how these things work: in C, the type of a pointer/function/array mess is declared by how it's used. For a declaration like "int ( * ( * foo)(void))[3]", you can read it as "for a variable foo, after computing the expression ( * ( * foo)(void))[3], the result is an int."<p>So one way to read C "gibberish" 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'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).
Hey, this is my site, first published 2009! This is the venerable cdecl enhanced with blocks support.<p>It used to be a shared host with a PHP script shelling out to the cdecl executable, written in K&R C. Now it's that same executable running on AWS Lambda.<p>Yes Lambda really will run arbitrary ELF binaries.
For all of its simplicity, the syntax for complex types in C is pretty horrible. Yes, I know the "inside out" rule, and can usually read these, but that doesn't make it any less bad.
I've been a professional C programmer for years, but I rarely find cdecl useful (command line or website). Not because complex C declarations are intuitive to me, but because cdecl fails on any unknown types. Real world C code is full of typedefs.
Back in early 2000s, we had bots on IRC doing this. My favorite technique was to pass the type to a template function, assign it to an integer and then parse the compile time error produced by gcc to extract the type.
on topic of function pointers, is there a template to turn<p><pre><code> std::funtion<foo(bar, baz)>
</code></pre>
into<p><pre><code> foo(*)(bar, baz)
?</code></pre>
The actual principle behind the C type declarations is "declaration follows use". Let me explain what this means. Take this declaration<p><pre><code> int *pi;
</code></pre>
Means that when I dereference the variable pi, I get an int. This also explains why<p><pre><code> int *pi, i;
</code></pre>
declares `pi` as a pointer to `int` and `i` as an `int`. From this point of view it makes sense stylistically to put * near the variable.<p>Declaration of array types is similar. For example,<p><pre><code> int arr[10];
</code></pre>
means that when I take an element of `arr`, I obtain an `int`. Hence, `arr` is an array of ints.<p>Pointers to functions work the same way. For example,<p><pre><code> int (*f)(char, double);
</code></pre>
means that if I dereference the variable `f` and I evaluate it on a `char` and on a `double`, then I get an `int`. Hence, the type of `f` is "pointer to function which takes as arguments a char and a double and returns an int".
tried: declare xxx as integer pointer to array of string equal to "mumu" and "kaka"<p>got: bad character '"'...apostrophe instead of double quote has the same result...well, I guess I expected too much