This seems to be the same as the cdecl program available in most Linux distributions (apt-get install cdecl).<p>Websites for these little utilities are definitely useful, though. :)
Neat site!<p><pre><code> // declare foo as pointer to function (void) returning pointer to array 3 of int
int (*(*foo)(void ))[3]
</code></pre>
That's actually a great example to throw at Go's syntax, which if you read from left-to-right, is perfectly one-to-one with the english:<p><pre><code> // declare foo as pointer to function (void) returning pointer to array 3 of int
var foo *func() *[3]int
</code></pre>
<a href="http://play.golang.org/p/1b48cjmZbx" rel="nofollow">http://play.golang.org/p/1b48cjmZbx</a>
This is a great helper for getting acquainted with the C spiral rule: <a href="http://c-faq.com/decl/spiral.anderson.html" rel="nofollow">http://c-faq.com/decl/spiral.anderson.html</a>
I also find this online utility useful when I don't have c++filt (another program available to Linux distros) available:<p><a href="http://pear.warosu.org/c++filtjs/" rel="nofollow">http://pear.warosu.org/c++filtjs/</a><p>This can be used to demangle C++ names.
I'm really surprised nobody's mentioned that this is an exercise from K&R (a.k.a. "The C Programming Language"), a must-read for any C programmer!<p><a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" rel="nofollow">https://en.wikipedia.org/wiki/The_C_Programming_Language</a>
This has some odd corner cases.<p>"void f(void)" -> "declare f as function (void) returning void"<p>"void fun(void)" -> "declare fun as function (void) returning void"<p>"void funct(void)" -> "declare funct as function (void) returning void"<p>"void func(void)" -> "syntax error"<p>"func" is not a special name in C.<p>Also:<p>"void fn(void f(void))" -> "syntax error"<p>But this syntax works just fine:<p><pre><code> /tmp$ cat test.c
#include <stdio.h>
void fn(void f(void))
{
f();
f();
}
void g(void)
{
puts("g");
}
int main()
{
fn(g);
return 0;
}
/tmp$ gcc test.c
/tmp$ ./a.out
g
g</code></pre>
the hell is this witchcraft? <a href="http://cdecl.ridiculousfish.com/?q=cast+foo+into+block%28int%2C+long+long%29+returning+double" rel="nofollow">http://cdecl.ridiculousfish.com/?q=cast+foo+into+block%28int...</a>
Note that this is “C gibberish <i>↔</i> English”, not just “to English”. So it also converts (specially-formatted) English to C gibberish. The second and third examples at the top demonstrate this feature.
I did something like this using C++ template metaprogramming, which means you can make use of the compiler to figure out the types for you, and you just have to write class templates to produce the English description. It's described at <a href="http://blog.asymptotic.co.uk/2011/02/c-type-declaration-decoder/" rel="nofollow">http://blog.asymptotic.co.uk/2011/02/c-type-declaration-deco...</a> , although somewhere along the line the markup got corrupted so the code samples don't quite render correctly.
I'm a fan of the 'c-spiral' rule/
<a href="http://c-faq.com/decl/spiral.anderson.html" rel="nofollow">http://c-faq.com/decl/spiral.anderson.html</a>
Cdecl is quite useful, but it does not work if you have declared your own types.<p>"Foo a" declares a of type Foo (whatever that is), but cdecl says Syntax Error.<p>It does not even work with C99 types. "bool a", "_Bool a", "int32_t a" all give Syntax Error.
I'd like to see an equivalent for parsing common shell commands and their arguments. Just converting the short form to the long form would be a good start
It can be a useful tool to get the main "feeling" in a complex line of pointers, but I wouldn't use it to auto-generate explainer comments