1

What's the significance of auto keyword from the programmer's perspective ? Its a default storage class for automatic variables which are allocated on stack and get deleted as their scope ends. So when this is the default behaviour what's the point of keeping this extra "not so significant" keyword ?

I recently started reading the "Expert C programming - Deep C secrets" where Peter Van Der Linden mentions that "auto keyword is apparently useless" but is meaningful for compiler writers in some way. What's that ? Can someone justify the existence of this keyword ?

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
anurag-jain
  • 1,380
  • 2
  • 11
  • 31
  • 1
    Because it's useless, its meaning has been changed in C++11. More information about the old storage class [here](http://stackoverflow.com/questions/1046477/is-there-any-reason-to-use-the-auto-keyword-in-c03?rq=1) – phuclv Jun 11 '14 at 16:15
  • A good explanation is provided [here][1]. [1]: http://stackoverflow.com/questions/1046477/is-there-any-reason-to-use-the-auto-keyword-in-c03 – unxnut Jun 11 '14 at 16:16
  • @unxnut If you're going to post a link to another QA on SO that answers the question, flag as a duplicate. – aruisdante Jun 11 '14 at 16:18
  • 1
    Does is carry same meaning in C11 as well ? And before someone mark it as duplicate the point of this question is to know in what way it was useful for the compiler designer(as specified in book) yet being redundant for the programmer? – anurag-jain Jun 11 '14 at 16:20
  • 2
    as I said, its meaning was changed in C11, and both the old and new meaning has been discussed in the link above. The reason was answered in [this link](http://stackoverflow.com/questions/23406212/why-does-auto-a-1-compile-in-c?rq=1): "This keyword is actually a leftover from C's predecessor B, where **there were no base types**: *everything* was int, pointer to int, array of int.(*) Declarations would be either auto or extrn [sic]. C inherited the "everything is int" as a default rule, so you could declare integers with" – phuclv Jun 12 '14 at 04:22
  • @LưuVĩnhPhúc: No, the meaning of `auto` did not change in C11; it still has the essentially useless meaning it had in C90 and C99. It changed in C++11. – Keith Thompson Jan 05 '16 at 23:59
  • The *keyword* is not meaningful to compiler writers except that they have to recognize it in the grammar. The concept it represents, namely *automatic storage duration*, is very meaningful to compiler writers, but it's not tied to the `auto` keyword. – Keith Thompson Jan 06 '16 at 00:05
  • @KeithThompson I wrote C++11 in the first comment but maybe I've misread the OP's comment below – phuclv Jan 06 '16 at 02:52

0 Answers0