digitalmars.D - Serious extern(C) bug
- =?UTF-8?B?Ikx1w61z?= Marques" (32/32) Sep 24 2013 Have you seen this one before? Do you know a workaround? (DMD
- growler (4/36) Sep 24 2013 don't you need extern __gshared on the var?
- growler (3/51) Sep 24 2013 http://dlang.org/interfaceToC.html (see last section at bottom of
- Walter Bright (6/38) Sep 24 2013 This x is put in thread global storage.
- =?UTF-8?B?Ikx1w61z?= Marques" (9/9) Sep 24 2013 Oops :-)
- Jacob Carlborg (6/9) Sep 25 2013 Well, C has thread local, via the extension "__thread" or via C++
- Iain Buclaw (6/15) Sep 25 2013 Especially considering that __thread is deprecated/error in D now. ;)
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
Sep 24 2013
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 42don't you need extern __gshared on the var? extern __gshared int x;
Sep 24 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:http://dlang.org/interfaceToC.html (see last section at bottom of page)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 42don't you need extern __gshared on the var? extern __gshared int x;
Sep 24 2013
On 9/24/2013 9:13 PM, "Luís Marques" <luis luismarques.eu>" 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 42So you've got two different x's here. Declare the first one as: __gshared int x = 0;
Sep 24 2013
Oops :-) I just assumed too quickly that it was another consequence of the DMD / (GCC, Clang) section mismatch I reported some days ago (http://forum.dlang.org/thread/gqxtzdbhnzkslnltqrmo forum.dlang.org), I didn't even think it was a basic PEBCAK. My bad --;; I guess I also implicitly assumed extern(C) implied __gshared... ("make it the same as C, not just the mangling"). And TLS is so implicit in D2 that one can even forget about it :-)
Sep 24 2013
On 2013-09-25 06:49, "Luís Marques" <luis luismarques.eu>" wrote:I guess I also implicitly assumed extern(C) implied __gshared... ("make it the same as C, not just the mangling"). And TLS is so implicit in D2 that one can even forget about it :-)Well, C has thread local, via the extension "__thread" or via C++ "thread_local". So if extern (C) implied "__gshared", how would one declare an extern (C) thread local variable? -- /Jacob Carlborg
Sep 25 2013
On 25 September 2013 10:40, Jacob Carlborg <doob me.com> wrote:On 2013-09-25 06:49, "Lu=EDs Marques" <luis luismarques.eu>" wrote:reI guess I also implicitly assumed extern(C) implied __gshared... ("make it the same as C, not just the mangling"). And TLS is so implicit in D2 that one can even forget about it :-)Well, C has thread local, via the extension "__thread" or via C++ "thread_local". So if extern (C) implied "__gshared", how would one decla=an extern (C) thread local variable? -- /Jacob CarlborgEspecially considering that __thread is deprecated/error in D now. ;) --=20 Iain Buclaw *(p < e ? p++ : p) =3D (c & 0x0f) + '0';
Sep 25 2013