On 9/24/2013 9:13 PM, "Luís Marques" <[email protected]>" wrote:
Have you seen this one before? Do you know a workaround? (DMD v2.063.2, on OX X
10.9)

file.d:

     extern(C)
     {
         int x = 0;

This x is put in thread local storage.

         void setx();
         void printx();
     }

     void main()
     {
         setx(); // sets x = 42
         writeln(x); // prints x = 0
         printx(); // prints x = 42
         x = 7;
         printx(); // prints x = 42
     }



file.c:

     #include <stdio.h>

     extern int x;

This x is put in thread global storage.


     void setx()
     {
         x = 42;
     }

     void printx()
     {
         printf("%d\n", x);
     }

Output:

     0
     42
     42

So you've got two different x's here.

Declare the first one as:

    __gshared int x = 0;

Reply via email to