`auto` keyword origins

Patrick Schluter Patrick.Schluter at bbox.fr
Mon Jun 26 14:44:48 UTC 2023


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](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1478.pdf) 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";




More information about the Digitalmars-d mailing list