The following seems to work in C++, but errors in D, why is that?

int foo(int* num) {
    {
        static int x = 10;
        x += 1;
        *num += x;
    }

    {
static int x = 20; // error: foo.x is already defined in another scope in foo
        x += 2;
        *num += x;
    }

    return 0;
}

https://dlang.org/spec/function.html#local-static-variables

Reply via email to