I'm currently reading "Expert C Programming - Deep C Secrets", and just came across this:
The storage class specifier
auto
is never needed. It is mostly meaningful to a compiler-writer making an entry in a symbol table — it says "this storage is automatically allocated on entering the block" (as opposed to statically allocated at compiletime, or dynamically allocated on the heap).auto
is pretty much meaningless to all other programmers, since it can only be used inside a function, but data declarations in a function have this attribute by default.
I saw that someone asked about the same thing here, but they don't have any answer and the link given in comments only explains why there's such a keyword in C, inherited from B, and the differences with C++11 or pre-C++11.
I'm posting anyway to focus on the part stating that the auto
keyword is somehow useful in compiler writing, but what is the idea nor the connection with a symbol table?
I really insist on the fact that I ask only about a potential usage when programming a compiler in C (not coding a C compiler).
To clarify, I asked this question because I'd like to know if there's an example of code where auto
can be justified, because the author stated there would be, when writing compilers.
Here the whole point is that I think to have understood auto
(inherited from B, where it was mandatory, but useless in C), but I can't imagine any example when using it is useful (or at least not useless).
It really seems that there isn't any reason at all to use auto
, but is there any old source code or something like that corresponding to the quoted statements?
Author answer: I just emailed Mr Van der Linden, and here is what he said:
I also asked for some explanation about what he meant by speaking about compiler writing and symbol table. Here is his response:
I guess I completely misunderstood his statements by thinking that
auto
may have some usages when writing a compiler in C, in the code dealing with symbol table, but it seems that he meantauto
is useless, but C compiler writers must handle it and understand it. I nevertheless asked him to confirm my mistake, and it was indeed a misunderstanding of mine :