Live data from Hacker News

Cdecl – Turns English phrases into C declarations

cdecl.org

11–20 of 56 posts

Re: Cdecl – Turns English phrases into C declarations

#13
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.

Re: Cdecl – Turns English phrases into C declarations

#14
The actual principle behind the C type declarations is "declaration follows use". Let me explain what this means. Take this declaration

   int *pi;
Means that when I dereference the variable pi, I get an int. This also explains why

   int *pi, i;
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.

Declaration of array types is similar. For example,

   int arr[10];
means that when I take an element of `arr`, I obtain an `int`. Hence, `arr` is an array of ints.

Pointers to functions work the same way. For example,

   int (*f)(char, double);
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".

Re: Cdecl – Turns English phrases into C declarations

#17
post #15

Its better to create a series of typedef and build up the declaration. Most of the time you need those sub typedef anyway.

Extremely sparingly, typedefs like in glib are a nightmare and just arbitrary typedefs like char -> char_t are just useless

Re: Cdecl – Turns English phrases into C declarations

#19
post #3

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." So one way to read C "gibberish" is to ignore the type at the beginning and parse the rest as an expression like a…

[deleted]
Post reply on HN