Scope storage class

Denis Koroskin 2korden at gmail.com
Wed Nov 26 16:49:12 PST 2008


27.11.08 в 01:12 Robert Jacques в своём письме писал(а):

> On Wed, 26 Nov 2008 13:24:57 -0500, Jarrett Billingsley  
> <jarrett.billingsley at gmail.com> wrote:
>> scope int b() { .. }
>>
>> The reason I wonder is because I would expect that the compiler is
>> still allocating the delegate on the heap if you use the first syntax.
>>  (the second is also shorter and clearer.)
>
> Just as a point of reference (in D1)
> scope Object a = new Object(); // Stack Allocated
> scope Object b;
> b = new Object(); // Heap Allocated
>
> So there may be some merit to scope int b() { .. } vs scope int b(); b =  
> {...}

If so, then why all the three usages

1) scope Object a;
2) scope Object a = b;
3) scope Object a = new Object();

are allowed when only 3rd one stack-allocates? I believe only third one  
should be allowed unless scope analisys is implemented (in its very basic  
form, at least):

scope Object a1 = new Object(); // ok
Object a2 = a1; // not ok
scope Object a3 = a1; // ok;
return a1; // not ok
return a2; // ok


More information about the Digitalmars-d-announce mailing list