Re:C2x: the next real revision of the C standard
by kazinator on Monday November 12, 2018 @01:49PM
(#18434657)
auto 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.
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:
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.