The auto
keyword is useless in the C language. It is there because before the C language there existed a B language in which that keyword was necessary for declaring local variables. (B was developed into NB, which became C).
Here is the reference manual for B.
As you can see, the manual is rife with examples in which auto
is used. This is so because there is no int
keyword. Some kind of keyword is needed to say "this is a declaration of a variable", and that keyword also indicates whether it is a local or external (auto
versus extrn
). If you do not use one or the other, you have a syntax error. That is to say, x, y;
is not a declaration by itself, but auto x, y;
is.
Since code bases written in B had to be ported to NB and to C as the language was developed, the newer versions of the language carried some baggage for improved backward compatibility that translated to less work. In the case of auto
, the programmers did not have to hunt down every occurrence of auto
and remove it.
It's obvious from the manual that the now obsolescent "implicit int" cruft in C (being able to write main() { ... }
without any int
in front) also comes from B. That's another backward compatibility feature to support B code. Functions do not have a return type specified in B because there are no types. Everything is a word, like in many assembly languages.
Note how a function can just be declared extrn putchar
and then the only thing that makes it a function that identifier's use: it is used in a function call expression like putchar(x)
, and that's what tells the compiler to treat that typeless word as a function pointer.
auto
can be specified but won't happen by default? – Manifesto