Hacker News new | ask | show | jobs
by mananaysiempre 1 day ago
Why would you do that? Ignoring for the moment arguments of prototypes and sizes of arrays, read C declarations the way they were designed: “char *a[<whatever>]” means that the expression *a[<whatever>] has type char; “char (*a(<whatever>))[<whatever>]” means that the expression (*a(<whatever>))[<whatever>] has type char; and so on. Then you apply the normal precedence rules for expressions, and in this case only knowing them for the prefix and postfix operators is sufficient. (Hint: all prefix operators have one precedence and all postfix ones another, and you know which one binds tighter if you know what *i++ means.)
1 comments

That’s exactly the same rule with more words (postfix = right, prefix = left).
I mean, yes, you’ve given a correct algorithm for parsing this simple precedence grammar, but it still leaves the impression that there’s something new to learn in addition to C expressions, whereas the whole point of the declaration syntax is that there largely isn’t.