www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __gshared on structs

reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
__gshared struct foo {
    int n;
}

foo f;

This f is not shared between threads, even though the
__gshared indicates it should be. Why is this not an error?

-- 
Simen
Aug 14 2010
parent reply Trass3r <un known.com> writes:
I don't think that this syntax is supported at all.
You need to use __gshared with the instance instead:
__gshared foo f;
Aug 14 2010
parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Trass3r <un known.com> wrote:

 I don't think that this syntax is supported at all.
 You need to use __gshared with the instance instead:
 __gshared foo f;
Hence my asking 'Why is this not an error?'. However, shared struct foo {} works, so one might expect symmetry to dictate that __gshared might, too. -- Simen
Aug 15 2010
parent reply Bernard Helyer <b.helyer gmail.com> writes:
On Sun, 15 Aug 2010 17:15:19 +0200, Simen kjaeraas wrote:
 Hence my asking 'Why is this not an error?'.
Because DMD ignores invalid attributes, and almost never flags them as an error (or even a warning!). `shared scope immutable import foo;` FWIW, I disagree with this behaviour -- SDC[1] will warn on no-op attributes. [1]:http://github.com/bhelyer/SDC
Aug 20 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Bernard Helyer:
 Because DMD ignores invalid attributes, and almost never flags them as an 
 error (or even a warning!).
Vote this: http://d.puremagic.com/issues/show_bug.cgi?id=3934 Bye, bearophile
Aug 20 2010