Bug 4377 – Support __gshared for easier D 2 compatibility
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2010-06-23T16:16:00Z
Last change time
2016-09-04T16:57:15Z
Assigned to
nobody
Creator
torhu
Comments
Comment #0 by torhu — 2010-06-23T16:16:31Z
It be would nice if D 1.x compilers accepted the __gshared keyword. The need for this comes up a lot when trying to make code that is ported from C work with both D 1 and D 2. Or even Java, this is an issue for DWT too.
One typical example that won't work in D 2 is this:
---
int x = 1;
int y = 2;
struct S { int* ptr; }
S[2] s = [{ &x }, { &y }];
---
Because the addresses of x and y are not known at link time in D 2, they are not accepted in static initializers.
x and y would typically be structs or function pointers, and the whole thing would be a lot more complex than this example. And there would be a whole lot of this stuff in the file too. Slapping a "__gshared:" on top of the file is an easy fix, but then it won't compile with D 1.x compilers.
I know there are several ways to make this work, but none of them are that nice. Using lots of big string mixins or moving all the initializers into module constructors? Ugh.
Since __gshared starts with two underscores, it shouldn't conflict with user code either.
Comment #1 by andrej.mitrovich — 2016-09-04T16:57:15Z
It's a bit late for this and D1 is no longer supported, closing.