6 ms·
C gibberish to English
- geofft 13y agoThis seems to be the same as the cdecl program available in most Linux distributions (apt-get install cdecl). Websites for these little utilities are definitely useful, though. :)
- RafiqM 13y agoOh, handy, never knew that existed.
- michaelcampbell 13y agoIndeed. It is quite old. I remember using the CLI version of this that I had to compile on my own in the early 90's on Solaris 2.x on a Sparc.
- jankins 13y agoThis is a great helper for getting acquainted with the C spiral rule: http://c-faq.com/decl/spiral.anderson.html http://c-faq.com/decl/spiral.anderson.html
- NAFV_P 13y agoThank you very much for the website.
- michaelcampbell 13y agoInterestingly, the "ultimate" example in that page fails to parse with the web cdecl.
- stephencanon 13y agoI've said it before (http://news.ycombinator.com/item?id=5080096 http://news.ycombinator.com/item?id=5080096), I'll say it again: the "spiral rule" makes pretty pictures, but it's nonsense.
- praptak 13y agoSomehow I cannot find those "spatial" (for lack of better name) rules useful. What works for me is "type declaration mimics usage". So I find the variable name, parse the declaration as usage and then reconstruct the type. It goes like this: char *((*foo)[3])(int); Ok, so if you dereference foo, then index[3], then call with int, then dereference, you get char? Cool, looks like foo is a pointer to an array of size 3 of functions that take int and return pointer to char.
- Keyframe 13y agothe hell is this witchcraft? http://cdecl.ridiculousfish.com/?q=cast+foo+into+block%28int%2C+long+long%29+returning+double http://cdecl.ridiculousfish.com/?q=cast+foo+into+block%28int...
- deleted 13y ago[deleted]
- ErsatzVerkehr 13y ago"Blocks" seem to be an Objective C feature. https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html https://developer.apple.com/library/ios/documentation/cocoa/...
- mikeash 13y agoTechnically an extension to plain C, with some Objective-C integration.
- MaxGabriel 13y agoApple extension to C language for blocks/lambdas. http://en.wikipedia.org/wiki/Blocks_(C_language_extension) http://en.wikipedia.org/wiki/Blocks_(C_language_extension)
- Keyframe 13y agoTat explains it why I haven't seen it then. I was afraid there for a second I was losing my mind.
- k4st 13y agoI also find this online utility useful when I don't have c++filt (another program available to Linux distros) available: http://pear.warosu.org/c++filtjs/ http://pear.warosu.org/c++filtjs/ This can be used to demangle C++ names.
- mjburgess 13y ago"I guess this'll be used mainly for function pointers"... first example.
- justinhj 13y agoI'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
- coherentpony 13y agoMaybe it's just me but having it written in English doesn't actually help me understand complex declarations.
- RossPenman 13y agoC gibberish to English gibberish.
- JoshTriplett 13y agoThis has some odd corner cases. "void f(void)" -> "declare f as function (void) returning void" "void fun(void)" -> "declare fun as function (void) returning void" "void funct(void)" -> "declare funct as function (void) returning void" "void func(void)" -> "syntax error" "func" is not a special name in C. Also: "void fn(void f(void))" -> "syntax error" But this syntax works just fine: /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
- nknighthb 13y agoNot sure what's going on with your second example, but that first one looks like an odd consequence of how a cdecl feature is implemented. cdecl doesn't just explain C declarations, it can also create them based on a more verbose pseudo-english language (the same one it spits out in response to being fed an actual C declaration, I believe). "func" is an alias for that language's reserved word "function".
- TorKlingberg 13y agoCdecl is quite useful, but it does not work if you have declared your own types. "Foo a" declares a of type Foo (whatever that is), but cdecl says Syntax Error. It does not even work with C99 types. "bool a", "_Bool a", "int32_t a" all give Syntax Error.
- brianmwaters_hn 13y agoI'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! https://en.wikipedia.org/wiki/The_C_Programming_Language https://en.wikipedia.org/wiki/The_C_Programming_Language
- jcox92 13y agoI'm a fan of the 'c-spiral' rule/ http://c-faq.com/decl/spiral.anderson.html http://c-faq.com/decl/spiral.anderson.html
- Madrigal 13y agoIt 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
- roryokane 13y agoNote that this is “C gibberish ↔ 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.
- tbyehl 13y agoI need a regex version of this.
- shurcooL 13y agoNeat site! // declare foo as pointer to function (void) returning pointer to array 3 of int int (*(*foo)(void ))[3] 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: // declare foo as pointer to function (void) returning pointer to array 3 of int var foo *func() *[3]int http://play.golang.org/p/1b48cjmZbx http://play.golang.org/p/1b48cjmZbx
- mistercow 13y agoI wonder how difficult it would be to write a C compiler (probably using LLVM would make sense) that translates an entire C program into English.
- fishpi 13y agoI 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 http://blog.asymptotic.co.uk/2011/02/c-type-declaration-decoder/ http://blog.asymptotic.co.uk/2011/02/c-type-declaration-deco... , although somewhere along the line the markup got corrupted so the code samples don't quite render correctly.
- KiwiCoder 13y agoCool idea, although I expect everyone who understands the English version would also have understood the C version.
- BlobbleBlab 13y agoFor most programmers, the C notation is probably easier to read / understand than the English gibberish derived from it with this tool
- nraynaud 13y agotoo bad it doesn't accept statements, I would be glad to get its take on a Duff's device.
- jloughry 13y agoShould anyone take this on (to write a version of cdecl that translates statements to English) as a personal challenge, please consider making it adaptable to whatever language is currently in fad for teaching beginning programming. This could be an extremely useful tool for teachers.