Proposal: new variable definition operator
Bill Baxter
dnewsgroup at billbaxter.com
Sat Apr 21 07:36:58 PDT 2007
Daniel Keep wrote:
>
> jovo wrote:
>> Daniel Keep Wrote:
>>> Just want to nitpick one thing: you seem to think that "auto" is the
>>> type inference keyword. It isn't. In D, a declaration is made up of
>>> four parts: the storage class, the type, the identifier and the initialiser.
>>>
>>> Obviously the identifier always needs to be there. If omitted, the
>>> initialiser is just type.init.
>>>
>>> Storage class and type are the interesting ones. In C, you could always
>>> omit the storage class if it was just a regular variable, but always had
>>> to specify the type. D allows you to omit the type if and only if you
>>> specify the storage class. Guess what the default storage class is?
>>>
>>> auto.
>>>
>>> Type inference in D isn't "type inference triggered by keyword", it's
>>> "type inference by omission." "auto" is only required so that the D
>>> grammar can tell it's supposed to be an declaration.
>>>
>> What is a meaning of auto as storage class specifier in D?
>> In C it signifyes an automatic variable (hence auto) with clear
>> definition.
>>
>> C++ faces similar problem introducing type inference via auto.
>> They will clear auto from list of storage class specifiers.
>> Just reusing old keyword with new meaning.
>>
>> jovo
>
> The auto storage class simply means that it's a "normal" variable: it's
> not constant, not final, not static and not scope-destroyed. If it's at
> module-level, it's a global variable at a fixed memory location. If
> it's in a function, it's allocated on the stack. If it's in a struct or
> class, it's allocated as part of the containing type.
>
> AFAIK, D's auto is the same as C's auto.
>
> Just to reiterate: auto has *nothing* to do with type inference. It's
> just that it happens to be the default storage class, and specifying the
> storage class allows you to omit the type. Any storage class can be
> used to trigger type inference.
>
> -- Daniel
Auto is for "automatic" variables which (at least in C) are just another
way to say local variables on the stack. Here's a particularly pathetic
Wikipedia article about it:
http://en.wikipedia.org/wiki/Automatic_memory_allocation
--bb
More information about the Digitalmars-d
mailing list