Hacker News new | ask | show | jobs
by 1ris 1900 days ago
"auto" in c is a storage class specifier, like "register", "extern" or "static".

https://en.cppreference.com/w/c/language/storage_duration

It was considered pretty useless by most, so c++11 recycled the keyword to mean something different.

2 comments

Auto is the implicit default right? As in function scoped, stack allocated, and lives until the function is returned?

K&R (Second Ed). Makes no mention of the auto keyword in Section 1.10, but it does say,

> Each local variable in a function comes into existence only when the function is called, and disappears when the function is exited. This is why such variables are usually known as automatic [sic] variables[...]

yes, exactly. That's why there is no need for it in modern c. This compiler however is different: The type is optional (and assumed to be int). Say you have a variable declaration "auto int i;". Back then you could omit int, now you can omit auto.