3 ms·
The question is, why doesn't C make char* a, b; apply the char* type to both? (That is, why didn't they design it that way?) I assume there was some reas
by kbenson 6y ago
The question is, why doesn't C make
char* a, b;
apply the char* type to both? (That is, why didn't they design it that way?)
I assume there was some reason originally, but it's made everything a bit more confusing ever since for a lot of people. :/
Edit: Apparently it's so declaration mirrors use. Not a good enough reason IMO. But plenty of languages have warts and bad choices that get brought forth. I'm a Perl dev, so I speak from experience (even if I think it's not nearly as bad as most people make out).
- TomSwirly 6y agoThis is why a lot of C people do one definition per line for any non-trivial variables.
- moth-fuzz 6y agoIn the olden days of C, pointers were not considered types on their own (you cannot have just a pointer, a pointer must point ‘to’ something, grammatically speaking). The type of the object of that declaration is a char. So it’s not really read as ‘I’m declaring a char-pointer called a’, it’s more along the lines of ‘I’m declaring an unnamed char, which will be accessed when one dereferences a’. Hence the * for dereferencing.
- deleted 6y ago[deleted]