Extern/scope issue

rikki cattermole rikki at cattermole.co.nz
Sat Apr 3 11:56:13 UTC 2021


--- main.d
module main;

extern(C) __gshared int foo;

import std;
void main()
{
     import foo : func;
     func;

     writeln(foo);
}

--- foo.d
module foo;
extern extern(C) __gshared int foo;

void func() {
     foo++;
}

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).


More information about the Digitalmars-d-learn mailing list