Add := digraph to D
Lars T. Kyllingstad
public at kyllingen.net
Thu Jun 21 02:14:40 PDT 2012
On Thursday, 21 June 2012 at 08:12:58 UTC, Jonathan M Davis wrote:
> On Thursday, June 21, 2012 08:04:35 Christophe Travert wrote:
>> "Lars T. Kyllingstad" , dans le message
>> (digitalmars.D:170370), a
>>
>> >>> auto name = initializer;
>> >>> const name = initializer;
>> >>> immutable name = initializer;
>> >>> shared name = initializer;
>> >>> enum name = initializer;
>> >>
>> >> After the first aren't these all just short hand for "const
>> >> auto name = init" etc with the given keyword?
>> >
>> > No. Many don't realise this, but "auto" doesn't actually
>> > stand
>> > for "automatic type inference". It is a storage class, like
>> > static, extern, etc., and it means that the variable stops
>> > existing at the end of the scope. It is, however, the default
>> > storage class, which is why it is useful when all you want is
>> > type inference. Even C has auto.
>>
>> auto is called a storage class, but where did you read that
>> auto would
>> make the variable stop existing at the end of the scope ?
>
> Yeah. I'm pretty darn sure that he's wrong on that. All auto is
> type
> inference. auto has no effect on the lifetime of a variable.
I admit that "stop existing at the end of the scope" was perhaps
imprecise to the point of being wrong. Here's Microsoft's
description of the auto storage class in C:
The auto storage-class specifier declares an
automatic variable, a variable with a local
lifetime. An auto variable is visible only in
the block in which it is declared.
All variables except those marked 'register', 'static' or
'extern' are 'auto' in C.
That said, I was still wrong. :) I just tried it now, and
apparently you can write pointless stuff like "auto extern int
foo;" and DMD will compile it just fine. (And, unless that is a
bug, it means D has redefined 'auto' to mean absolutely nothing,
except to be a marker saying "this is a declaration", allowing
one to omit both storage class and type.)
auto should probably be removed from the list of storage classes
in the D spec, then.
> _All_ variables
> cease to exist when they exit scope.
Not static ones, but again maybe you took "stop existing" to
refer to the name rather than the storage.
-Lars
More information about the Digitalmars-d
mailing list