6 ms·
Dunno how this is supposed to be worded, but it's because the "pointerhood" is tied to the variable being declared, not the type itself. This becomes obvious wh
by onre 2y ago
Dunno how this is supposed to be worded, but it's because the "pointerhood" is tied to the variable being declared, not the type itself. This becomes obvious when you declare multiple variables at once.
char* cat, dog; /* one char pointer, one char */
char *cat, *dog; /* two char pointers */
- teo_zero 2y agoRight. It would be nice if C allowed types and variables to be separated, we could even defines arrays like this: char[8] buffer; Alas, it's not the syntax Dennis Ritchie settled upon.
- cb321 2y agoThe trade-off is one vs. two operator sub-syntaxes or in other words "sub-syntax economy". As it is, C has just one operator expression syntax (and one set of operator precedences/associativities). The "forward applicative" expression syntax is "reused" in the "backward" or "inverse" type declarations.
- kevin_thibedeau 2y agoThe minor problem is that a typedef pointer breaks this pattern: typedef foo * FooP; FooP a, b; // Both are pointers Pointer typedefs are misguided but there is no denying that C is inconsistent on whether the '*' is part of the type or not.