Scope storage class

Sergey Gromov snake.scaly at gmail.com
Wed Nov 26 14:27:22 PST 2008


Wed, 26 Nov 2008 17:02:54 -0500, bearophile wrote:

> While on DMD 1.036 the following code:
> 
> // code #2
> import std.c.stdio: printf;
> 
> int a(int k, lazy int x1, lazy int x2, lazy int x3, lazy int x4, lazy int x5) {
>     int b() {
>         k -= 1;
>         return a(k, b(), x1, x2, x3, x4);
>     }
>     return k <= 0 ? x4 + x5 : b();
> }
> 
> void main() {
>     printf("%d\n", a(24, 1, -1, -1, 1, 0));
> }
> 
> Outputs at compile time:
> 
> man_or_boy2.d(6): delegate man_or_boy2.a.b.__dgliteral1 is a nested function and cannot be accessed from a
> man_or_boy2.d(6): delegate man_or_boy2.a.b.__dgliteral2 is a nested function and cannot be accessed from a
> man_or_boy2.d(6): delegate man_or_boy2.a.b.__dgliteral3 is a nested function and cannot be accessed from a
> man_or_boy2.d(6): delegate man_or_boy2.a.b.__dgliteral4 is a nested function and cannot be accessed from a
> man_or_boy2.d(6): delegate man_or_boy2.a.b.__dgliteral5 is a nested function and cannot be accessed from a
> 
> But this code works on the codepad site, that uses DMD v.1.026 (I think with Tangobos), up to N=21 (then the site goes into timeout for safety):
> http://codepad.org/8GtKswm8

[snip]

> All the following compilations are done with and N=20 and:
> dmd -O -release -inline -L/STACK:1700000000 man_or_boy.d
> dmd -O -release -inline -L/STACK:1700000000 man_or_boy2.d

Remove -inline from your compiler options, and #2 compiles and runs
faster in both D1 and D2 than #1.

lazy seems to do something funny when -inline is in effect.


More information about the Digitalmars-d-announce mailing list