On Monday, 26 June 2023 at 00:00:48 UTC, Alexander Tretyak wrote:
> I'm just curious when was the auto
keyword introduced in D?
The reason I am asking is because D language appeared in 2001, but C++ proposal with auto
keyword new semantics dated April 28, 2003.
I always thought that auto
in D was taken from C++. But what if it is opposite, i.e. C++11's auto
was inspired by D's auto
?
auto is a C keyword defining the storage class of a variable. It's placed at the same place as register/const and static.
In D it has the same role (i.e. it's a storage class). The type inference has nothing to do with auto. It is just necessary for the grammar to represent a type of a declaration.
a=1;
if the type is omitted, the parser cannot distinguish between a declaration with initialiser or an assignment. You have to put either a type or a storage class to disambguate
const a=1;
immutabe b=2L;
auto c=5.4;
static d=w"Hello";