Extern/scope issue

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


> The __gshared is irrelevant to it working between modules, but 
> it is relevant if you want C compatibility between threads 
> (NOTE: extern(C) sets mangling, otherwise the module would be 
> encoded in its name).
Solved:
The following produces the expected result.
However, changing extern(C) to extern(D) causes linker failures.
To me, that is bizarre.
Testmain:
extern(C) 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:
extern extern(C) int xvar;
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