The C23 standard apparently has introduced using "auto" keyword for auto type deduction, see here, just like in C++11. However, there seems to be some differences.
According to here, https://en.cppreference.com/w/cpp/keyword/auto, after C++11, auto
is no longer a storage duration specifier in C++.
However, I cannot easily find an equivalently statement for C23. Is it the case that auto
is still a storage class specifier in C in C23?
Can we still write int auto x = 1;
in C23?
EDIT: The answer to the first question is yes. But as pointed out by Andrew Henle in comments below, the second question is different:
Can we still write float auto x = 1;
in C23?
As quoted by @AndrewHenle and @VladfromMoscow, in the standard document, 6.7.1 Storage-class specifiers, paragraph 4
auto shall only appear in the declaration specifiers of an identifier with file scope or along with other storage class specifiers if the type is to be inferred from an initializer.
It seems that this does not cover the case float auto x = 1;
, if this declaration is not in file scope.
What's the interpretation of this?
There is another question: the sentence seems confusing because we surely can use auto without "other storage specifiers", couldn't we? Like auto a = 1;
.
auto
while adding something close to the C++11 and later use ofauto
for type inference, likely as an attempt to not break legacy code. But I'll defer to those more astute in reading the C standard than I am (and it's also a draft...) – Zacharauto
in this declaration (in particular not the one you quote, since no type is inferred) and it has no effect (as in previously in C). – Bilberryauto
in this declaration This seems to: "auto
shall only appear in the declaration specifiers of an identifier ... if the type is to be inferred from an initializer." If the type is not to be inferred from an initializer, that can be read as "auto
shall not appear...", which sure sounds like it could be read as a prohibition to me. The standard here is as clear as mud. :-/ – Zacharauto
can certainly be used without other storage class specifiers, because that's how we useauto x = 1;
. It is confusing. – FyrdX shall only do Y if Z
withor
as part ofY
. And that structure to me intuitively seems to formalize to(X does Y) implies Z
, rather thanZ implies (X does Y)
or evenZ is equivalent to (X does Y)
. But I don't know whether linguistically there is any support for that. However my reading would make sense in keeping old usage as well as the new form valid while making e.g.auto static int x = 0;
invalid as it should be. – Bilberryauto
can be found here: open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm – Zachar