3 ms·
It is easier to parse and you don't get the abomination that is C function pointers
by Yujf 4y ago
It is easier to parse and you don't get the abomination that is C function pointers
- MathMonkeyMan 4y agoIt makes me wonder why C put the ultimate type on the left and not on the right. C type/variable declarations are an expression that transforms the type/variable into a primitive type, which is then annotated on the left of the expression. Why not on the right?
- jstimpfle 4y agoBecause parsers, like humans, read from left to right. Important parsing decisions are usually made as early as possible. An example is recursive descent parsing, which derives its simplicity from making decisions first, allowing a top-down parse. And when humans skim text, I bet it can be shown that it's easier if the syntactically significant locations are aligned near the beginning of each statement.
- jejones3141 4y agoThe intent, as I understand it, is that "declaration should look like use", so that the base type is on the left. If you declare int *foo; then *foo is an int. IMHO the existence of "cdecl" is evidence that it might not have been the right choice.
- imtringued 4y agoDeclaration should look like use is nonsense though. I mean, what is the practical benefit of putting the pointer to the left of the name instead right to the type? For pointers the difference is literally just on which side of the space the asterisk sits at the expensive of making it unreasonably difficult to represent nesting of type constructs.
- UncleEntity 4y agoIt’s super easy to parse, I added types to a JavaScript parser I play around with in maybe a half an hour just to see if I liked it. It probably helped that I just parse to an AST that’s generated so experiments like this are trivial.
- jounker 4y agoIt’s super easy to parse until you have interesting higher order functions.