Hey, this is my site, first published 2009! This is the venerable cdecl enhanced with blocks support. 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. Yes Lambda really will run arbitrary ELF binaries.
Didnt know what blocks are , it seems it's an apple extension.
Cdecl – Turns English phrases into C declarations
31–40 of 56 posts
Re: Cdecl – Turns English phrases into C declarations
#32Here'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." So one way to read C "gibberish" is to ignore the type at the beginning and parse the rest as an expression like a…
It is notable that the chapter in K&R which discusses declarations also presents a partial version of the cdecl program and one of the exercises is for the reader to complete it --- really helping to dispel the notion that compilers are not mysterious magic. In my experience, it's rare for an introductory book on a programming language to also contain such "hints" on how it could be implemented.
Re: Cdecl – Turns English phrases into C declarations
#33If I recall correctly, this one came as an exercise in Knuth's book of C programming, ibidem were C declarations and priorities explained.
Knuth does not use C in his books.
Re: Cdecl – Turns English phrases into C declarations
#34Earlier quoted context omitted.
How about just using Ada? It has the added bonus of not being a gimmick (depending on who you ask I suppose ; ) Ada: type Ret_Typ is array (1..3) of Integer; Foo : access function return not null access Ret_Typ := null; C: int ((foo)(const void *))[3] Cdecl: declare foo as pointer to function (pointer to const void) returning pointer to array 3 of int
In the interest of furthering annoying language smuggery, the rough Rust equivalent: foo: fn() -> Box Alternately, if the pointer is into static memory and not something allocated on the heap: foo: fn() -> &'static ; That's pretty nice to look at and not too hard to read. In my opinion, for commonly used syntax (like fn decls), some well-chosen punctuation marks (', ->, :, in this case) are often boon to readability…
There's really no need to box a 12-bytes array in the first place.
Re: Cdecl – Turns English phrases into C declarations
#35Earlier quoted context omitted.
How about just using Ada? It has the added bonus of not being a gimmick (depending on who you ask I suppose ; ) Ada: type Ret_Typ is array (1..3) of Integer; Foo : access function return not null access Ret_Typ := null; C: int ((foo)(const void *))[3] Cdecl: declare foo as pointer to function (pointer to const void) returning pointer to array 3 of int
In the interest of furthering annoying language smuggery, the rough Rust equivalent: foo: fn() -> Box Alternately, if the pointer is into static memory and not something allocated on the heap: foo: fn() -> &'static ; That's pretty nice to look at and not too hard to read. In my opinion, for commonly used syntax (like fn decls), some well-chosen punctuation marks (', ->, :, in this case) are often boon to readability…
Just meaning the website CDecl - its a neat tool to make C readable in English, but Ada is a real language used to make planes fly etc. Many people have contempt for it though which is why I made the joke xD
Interesting that you can note which type of memory an anonymous type comes from in Rust. I suppose its for optimization purposes? Doesn't seem that helpful from a pure typing perspective.
As an aside I doubt a layman would be able to understand that notation in Rust, whereas my girlfriend might be able to grasp or read Ada code or the output of CDecl.
Re: Cdecl – Turns English phrases into C declarations
#36Here'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." So one way to read C "gibberish" is to ignore the type at the beginning and parse the rest as an expression like a…
How about just using Ada? It has the added bonus of not being a gimmick (depending on who you ask I suppose ; ) Ada: type Ret_Typ is array (1..3) of Integer; Foo : access function return not null access Ret_Typ := null; C: int ((foo)(const void *))[3] Cdecl: declare foo as pointer to function (pointer to const void) returning pointer to array 3 of int
1. The syntax isn't "type id, id, id;", it's "type expr, expr, expr;" The trend for C-style languages have been to move to the former type syntax, so C/C++ is the anomaly here.
2. Pointer declarators show up to the left of the name while function and array declarators show up to the right of the name. This means you can't figure out the type by scanning in one direction. Contrast this with LLVM, where function arguments and pointer types both go to the right of the leaf type (while arrays are infix), or Rust, where they both live on the left of the leaf type.
Re: Cdecl – Turns English phrases into C declarations
#37Earlier quoted context omitted.
How about just using Ada? It has the added bonus of not being a gimmick (depending on who you ask I suppose ; ) Ada: type Ret_Typ is array (1..3) of Integer; Foo : access function return not null access Ret_Typ := null; C: int ((foo)(const void *))[3] Cdecl: declare foo as pointer to function (pointer to const void) returning pointer to array 3 of int
I'm not defending C's syntax as sane here, because it's not. It boils down to have two problems: 1. The syntax isn't "type id, id, id;", it's "type expr, expr, expr;" The trend for C-style languages have been to move to the former type syntax, so C/C++ is the anomaly here. 2. Pointer declarators show up to the left of the name while function and array declarators show up to the right of the name. This means you can't…
Re: Cdecl – Turns English phrases into C declarations
#38tried: declare xxx as integer pointer to array of string equal to "mumu" and "kaka" got: bad character '"'...apostrophe instead of double quote has the same result...well, I guess I expected too much
Re: Cdecl – Turns English phrases into C declarations
#39 std::funtion
into foo(*)(bar, baz)
?Re: Cdecl – Turns English phrases into C declarations
#40Earlier quoted context omitted.
I'm not defending C's syntax as sane here, because it's not. It boils down to have two problems: 1. The syntax isn't "type id, id, id;", it's "type expr, expr, expr;" The trend for C-style languages have been to move to the former type syntax, so C/C++ is the anomaly here. 2. Pointer declarators show up to the left of the name while function and array declarators show up to the right of the name. This means you can't…
Reading for both ends is maddening for seasoned devs, but in a general sense most languages are symbol salads these days for arbitrary, subjective reasons. The decisions made during the C development to squeeze the juice out of 60 character wide terminals haunt us to this day... like case sensitivity
What's wrong with case sensitivity?