www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - `auto` keyword origins

reply Alexander Tretyak <alextretyak2 gmail.com> writes:
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`?
Jun 25 2023
next sibling parent reply Adam D Ruppe <destructionator gmail.com> writes:
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?
What's New for D 0.137 Oct 24, 2005 New/Changed Features Added implicit type inference. from: https://digitalmars.com/d/1.0/changelog1.html Though the auto keyword was around earlier (it actually comes from old C), and technically doesn't mean exactly what you think it means - the `auto` keyword isn't what's magic, you can use many others in its place (most the time) like `const` and `immutable` among more - but the feature referred to is the type inference.
 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`?
It probably went both ways. The C++ proposal you linked is definitely earlier than D adopting the thing, and perhaps D's use of it helped prompt the C++ committee to adopt it too.
Jun 25 2023
parent Alexander Tretyak <alextretyak2 gmail.com> writes:
Thanks for the reply!
Jun 25 2023
prev sibling parent Patrick Schluter <Patrick.Schluter bbox.fr> writes:
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";
Jun 26 2023