D newb

bearophile bearophileHUGS at lycos.com
Mon Aug 18 03:38:39 PDT 2008


Joel Anderson:
> > bearophile:
> >> 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).
>
> If the class has a component sub-class the component may be heap 
> allocated.  I don't agree with making that an error though.

May I ask you why you don't like that as an error?
Generally I don't like undefined situations, if I add the 'scope' keyword I want the class to be stack-allocated, and I assume the compiler does that. Then the layout of the memory used by the code is different, and I can for example take care to avoid a stack overflow. If the compiler at compile time is able to tell me that the class can't be allocated on the stack, then I think the program has to not compile until I remove the 'scope' keyword there. This makes the code reflect what the program actually does.

Bye,
bearophile



More information about the Digitalmars-d mailing list