Scope storage class

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Nov 26 10:24:57 PST 2008


On Wed, Nov 26, 2008 at 11:07 AM, bearophile <bearophileHUGS at lycos.com> wrote:
>> Can you try declaring b as a nested function instead of as a delegate
>> literal and see if that helps?
>
> I think that may lead to nonworking code.

Uh, why?  You are declaring the delegate as 'scope', yes?  Meaning you
don't expect the delegate to be allocated on the heap?  Why don't you
try it and see what happens instead of arguing?

>> (why are you declaring it the way you are, anyway?
>
> Here you can find explanations:
> http://en.wikipedia.org/wiki/Man_or_boy_test
>
> Here you can find other two versions that work, but I think the version I have shown is the more robust one (that is: able to computer up to higher N values with D1 compiler):
> http://www.rosettacode.org/wiki/Man_or_boy_test#D

I don't really care about what test it is.  I'm just confused why you're doing:

scope int delegate() b;
b = { .. };

instead of:

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.)


More information about the Digitalmars-d-announce mailing list