4 ms·
Auto is already taken in C. It’s the default, rather than register or static, so you hardly ever see it
by jfoutz 8y ago
Auto is already taken in C. It’s the default, rather than register or static, so you hardly ever see it
- kazinator 8y agoauto was taken in exactly the same way in C++ until fairly recently. They re-purposed it because it was obsolescent. auto was already in vanishing disuse in C at the time ANSI C came out in 1989. The C++ use of auto resurrects an aspect of the way auto was used in the C predecessor languages B and NB. In these pre-C languages, everything was an integer cell. A declaration of local variables looked like this: auto x, y; the auto meant automatic storage (stack), but the real purpose here is syntactic: the auto is a declaration specifier, which makes the above construct a declaration. There is no indication of type, because it is implicit. Without the auto it would look like a comma expression with no effect. This implicit typing survived into C for "implicit int" return values, like "main () {...}". But type specifiers were introduced and became mandatory in declarations, and so auto became unnecessary verbiage since all it did now was specify a storage class that was already the default one. C++ resurrect the syntactic use of auto in a way: once again, it provides declaration syntax that allows the type specifier to be omitted. This time, of course, that type is inferred rather than assumed integer.
- jfoutz 8y agoThis is a great thoughtful reply to my terse, shallow comment. Thank you. It’s insightful