D newb

Steven Schveighoffer schveiguy at yahoo.com
Sun Aug 17 18:27:56 PDT 2008


"bearophile" wrote
> Robert Fraser:
>> scope Foo f = new Foo();
>>
>> The "scope" keyword in the declaration says to the compiler "this will
>> not escape the function" thus creating the data on the stack. "f" is
>> still a reference type in this case, however (although it may not be
>> implemented as a reference -- that's up o the compiler).
>
> But the 'scope' works only in some situations, the original poster can 
> take a look at the docs about 'scope'.
>
> My question: does the compiler raise a compilation error if the 'scope' 
> keyword is used where the compiler can't actually allocate the class on 
> the stack? (if not, then I think it may be better for the compiler to 
> raise such error, avoiding the illusion of efficiency).

In what situations does it not work?

As long as the class is not too large for the stack (which is very 
unlikely), it should be able to allocate.

-Steve 





More information about the Digitalmars-d mailing list