Extern/scope issue

DLearner bmqazwsx123 at gmail.com
Sat Apr 3 11:34:06 UTC 2021


Tried the following, same result (1,0,2,1):
testmain:
__gshared int xvar;
import testmod;

void main() {
    import std.stdio;

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

    writeln("Leaving: main");
}

testmod:
void testsub() {
    __gshared int xvar;

    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