Serious extern(C) bug
growler
growlercab at gmail.com
Tue Sep 24 21:36:36 PDT 2013
On Wednesday, 25 September 2013 at 04:35:35 UTC, growler wrote:
> On Wednesday, 25 September 2013 at 04:13:02 UTC, Luís Marques
> 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;
>> 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;
>>
>> void setx()
>> {
>> x = 42;
>> }
>>
>> void printx()
>> {
>> printf("%d\n", x);
>> }
>>
>> Output:
>>
>> 0
>> 42
>> 42
>
> don't you need extern __gshared on the var?
>
> extern __gshared int x;
http://dlang.org/interfaceToC.html (see last section at bottom of
page)
More information about the Digitalmars-d
mailing list