Auto syntax revisited
Sean Kelly
sean at f4.ca
Mon Feb 20 13:07:20 PST 2006
Fredrik Olsson wrote:
> After some discussion on #d I though why not put my thoughts into more
> permanent writing.
>
> Keyword auto is used for two reasons; implicit type and making sure the
> object is destroyed when going out of scope. I suggest a new keyword for
> the latter: local.
>
> local auto foo = new Bar();
If we're moving towards stack-based auto classes then I'd prefer the
distinction be associated with the object and not the reference. ie.
auto foo = local Bar();
I think the distinction is important because foo can be reassigned to a
non-local object. Alternately, simply omitting 'new' entirely might be
feasible, though the meaning there is less obvious. As I said in #d:
Foo Bar() { return new Foo(); }
auto foo = Bar();
looks like a stack-based initialization even though it's not. But
perhaps it doesn't matter in this case, as nothing will break if a
heap-based instance is used in place of a stack-based instance, it's
replacing things the other direction that can cause problems.
Sean
More information about the Digitalmars-d
mailing list