4 ms·
It 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/variab
by MathMonkeyMan 4y ago
It 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.