auto storage class - infer or RAII?

Sean Kelly sean at f4.ca
Mon Nov 13 14:17:51 PST 2006


Walter Bright wrote:
> Sean Kelly wrote:
> 
>> If we are truly to use the 'scope' keyword for RAII objects, I humbly 
>> request that the data be flagged instead of the reference.  Here are 
>> two suggestions for syntax:
>>
>>     MyClass c = scope MyClass();
>>     MyClass c = new(scope) MyClass();
>>
>> Both would allow data to be allocated on the stack without escape 
>> detection (or an assumption that the user isn't being evil), and the 
>> latter is even almost identical to how alloca is used now.  I dislike 
>> that both would make class allocation semantically different from 
>> concrete type allocation, but anything is better than associating 
>> 'scope' with the reference itself, for the reasons illustrated above.
> 
> It's a good idea, but there's currently no way to flag data itself in 
> this way.

Hrm... so the compiler would have to do something like generate a dummy 
variable referencing the class instance and act on that instead, and 
count on the optimizer to throw away the dummy variable when 'c' isn't 
reassigned in the enclosing scope.  I suppose that could be a bit 
confusing when debugging... and some might complain about the 
unpredictable stack frame size or some such.  Well darn :-)


Sean



More information about the Digitalmars-d mailing list