Extern/scope issue

rikki cattermole rikki at cattermole.co.nz
Sat Apr 3 10:05:45 UTC 2021


On 03/04/2021 11:01 PM, DLearner wrote:
> 'Testmain' imports module 'testmod'.
> Both are shown below.
> I expected 1,1,2,2.
> I got 1,0,2,1 - which speaks to scope/extern misunderstanding
> 
> Any ideas?
> Best regards
> 
> Testmain:
> 
> int xvar;

TLS variable with D mangling, not a c global.

> 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() {
> 
>    extern(D) int xvar;

That is a regular variable.
Setting the calling convention/mangling like that doesn't make any sense 
and shouldn't be allowed in context.

>    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