Extern/scope issue

DLearner bmqazwsx123 at gmail.com
Sat Apr 3 11:47:04 UTC 2021


> https://dlang.org/spec/attribute.html#gshared
>
> However, you should be using the module system for accessing 
> globals, rather than redeclaring them.

If the module system is dumped, and evrything put into one file, 
works perfectly.
With or without __gshared in from of 'int xvar'.

int xvar;
void main() {
    import std.stdio;

    writeln("Entering: main");
    xvar = 1;
    writeln("xvar=", xvar);
    testsub();
    writeln("xvar=", xvar);

    writeln("Leaving: main");
}

void testsub() {
    import std.stdio;

    writeln("Entering: testsub");
    writeln("xvar=", xvar);
    xvar = 2;
    writeln("xvar=", xvar);
    writeln("Leaving: testsub");
}



More information about the Digitalmars-d-learn mailing list