Auto syntax revisited

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Tue Feb 21 11:57:52 PST 2006


Fredrik Olsson wrote:
> Ivan Senji skrev:
> 
>> I think I agree (although not 100% certain yet)
>> Think it would be cool if local men't destruct at end of scope no 
>> mater is the actual instance created in this function or not.
>>
>> Stack objects could still be created something like:
>> auto foo = Foo(); or maybe
>> auto baz = stack Foo(); or something else
>>
>> I somehow feel these features might complicate the language a lot.
> 
> 
> I better write a summary :), with this my first proposal we really just 
> have four cases:
> 
> // Object allways on heap, created from class, gc destroys whenever,
> // Object can be passed out of scope
> Foo foo = new Foo();
> 
> // Object allways on heap, created from another function,
> // gc destroys whenever, object can be passed out of scope
> Foo foo = Bar();
> 
> // Object could be on stack, created from class, scope exit destroys

Everything sounds cool, but that *could* part troubles me :)
It should either mean stack, or heap, or have a choise over that.

> // imidiately, can not be passed out of scope
> Foo foo = local new Foo();
> 
> // Object allways on heap, created from another function, scope exit
> // destroys imidiately, can not be passed out of scope.
> Foo foo = local Bar();
> 
> And then auto could be used instead of Foo to declare the type, but that 
> is beyond this discussion, and implied by auto _only_ meaning implicit 
> type and nothing else.
> 
> Since objects that are potentially on the stack can not pass out of 
> scope, and if sent as argument to other function they are just pointers 
> anyway, there should be no requirements for changing any ABI.
> 
> Only addition is that local object on heap must be destroyed in the 
> process of unwinding an exception. So any scope that uses local objects 
> on heap must have an implicit try {} finally {} for releasing objects.
> 
> // Fredrik Olsson



More information about the Digitalmars-d mailing list