Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • This is useful if you're far from the internet. Here's a web site that translates the gibberish to English or vice versa:

    https://cdecl.org/

    Or

      apt install cdecl
    
    on Linux.
  • My ideal syntax for function pointers is:

      fn signal(signum: int, fp: fn(int -> void)) -> fn(int -> void)
    
    It keeps the parameter and return types inside, makes it obvious that it's a function using the fn keyword (or func or whatever), short and readable.

    When you add more parameters you get `fn(int, char -> int)`. That's the only sane way to handle it and it also supports multiple return values if you want them.

    Bonus: all type modifiers should be prefix like `?*MyStruct` and control flow should be postfix `task.await.match { ... }`. Every language should either have a pipe operator or let you call any function with method syntax. `x |> f |> g` is better than `g(f(x))`.

  • This comes up every so often, and while it's sort of almost true and attractive, it isn't actually correct.

    The correct rule is "follow the C grammar". An easier to remember and also correct rule is "start at the identifier being declared; work outwards from that point, reading right until you hit a closing parenthesis, then left until you hit the corresponding open parenthesis, then resume reading right..." (this is sometimes called the "right-left rule": https://cseweb.ucsd.edu/~gbournou/CSE131/rt_lt.rule.html).

  • > "str is an array 10 of pointers to char"

    Wow, imagine if it was possible to actually use a language like that do declare the type of the variable like that? Something like

        str: array [0..9] of ^Char; 
    
    or even

        var str [10]*uint8
    
    Just imagine...
  • D simply reads right to left:

        int[]* p; // pointer to array of int
        int function(char*) fp; // pointer to function with char* parameter returning an int
  • Related. Others?

    C "clockwise/spiral" rule to understand declarations - https://news.ycombinator.com/item?id=42564861 - Jan 2025 (75 comments)

    Clockwise/Spiral Rule - https://news.ycombinator.com/item?id=25494219 - Dec 2020 (16 comments)

    The Clockwise/Spiral Rule of C declarations - https://news.ycombinator.com/item?id=12775735 - Oct 2016 (68 comments)

    The “Clockwise/Spiral Rule” - https://news.ycombinator.com/item?id=8648287 - Nov 2014 (26 comments)

    The Clockwise/Spiral Rule - https://news.ycombinator.com/item?id=6471202 - Sept 2013 (7 comments)

    The "Clockwise/Spiral Rule" in C - https://news.ycombinator.com/item?id=5079787 - Jan 2013 (45 comments)

    by dang
  • Learning this rule will mean you miss out on the opportunity to use one of the best words in the English language, which is “boustrophedonically” (meaning alternating left to right with right to left “as an ox ploughs a field”[1]).

    C is parsed boustrophedonically.

    [1] This is apparently the ancient Greek origin of the word.

  • Being taught this rule in undergrad really hampered my appreciation of C. As I've said in a previous comment, the real key that unlocked understanding C declarations for me is the mantra "declaration follows use." You declare a variable in C in exactly the same way you would use it: if you know how to use a variable, then you know how to read and write a declaration for it. Once I understood this elegant idea, it became hard to enjoy using statically typed languages that eschew it.

    It is explained in more detail at this link: https://eigenstate.org/notes/c-decl

Explore Birbla archives