Add := digraph to D
Jonathan M Davis
jmdavisProg at gmx.com
Thu Jun 21 01:12:40 PDT 2012
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. _All_ variables
cease to exist when they exit scope. And reference and pointer types continue
to exist on the heap (it's just that the pointer or reference is gone) without
being destroyed or freed or whatnot. So, I don't know where Lars got the idea
that auto was anything other than type inference. Sure, it might be termed a
storage class, but that term seems to be pretty much meaningless in D.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list