I need to clarify some things that have confused me a few times. I've reconsidered these basic attributes a few times, and I thought I understood them, but I obviously don't.<div><br></div><div>The case that has confused me is here:
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=7897">http://d.puremagic.com/issues/show_bug.cgi?id=7897</a><br><div><br></div><div>In the global scope:</div>
<div><br></div><div>int x; <- x is TLS</div><div><br></div><div>but:</div><div><br></div><div>static int x; <- this is... a 'static' global instance, whatever that means? Is this TLS or not? If so, how is it distinct from 'int x;' above? I presume it must still be TLS, and effectively meaningless at the global scope; <a href="http://dlang.org" target="_blank">dlang.org</a> states "static is ignored when applied to other declarations". It is just used for members of struct/classes? Why not produce a syntax error rather than ignore it?</div>
<div><br></div><div>immutable int x; <- this can't possibly change, so why would it be TLS? it must be a single static instance... right?</div><div><br></div><div>__gshared int x; <- this should behave exactly like a C global right? ie, no TLS + addressable at compile time.</div>
<div><br></div><div>static immutable x; <- i've seen this a few times, what does it mean?</div><div><br></div><div><br></div><div>I'm concerned with which of these are addressable at compile time. By my logic, all (well, perhaps not the first) should be allocated in the datablock, addresses known at compile time, and therefore addressable at compile time (ie, able to alias in template args).</div>
<div>That doesn't seem to be the case however in at least the __gshared case (in my big report above), which is very surprising to me.</div><div><br></div><div>There's another thing that that's had me scratching my head for a while, and gave me the contradictory feeling that the use of TLS data is fairly relaxed:</div>
<div><br></div><div>struct S</div><div>{</div><div> int x;</div><div> static int y;</div><div>}</div><div><br></div><div>In this case y is static, ie, globally shared by all instances, but I expect it SHOULD be TLS, since it is mutable, and therefore not thread safe...</div>
<div>That said, I write code that passes static members of structs into templates as alias parameters all the time, and generate code that writes to them.</div><div>How is this possible? And given that it is, why is it not possible for at least __gshared at global scope?</div>
<div><br></div><div><br></div><div><div>struct S</div><div>{</div><div> static x;</div><div> __gshared y;</div><div>}</div><div><br></div></div><div>What is the difference between x and y here?<br class="Apple-interchange-newline">
</div><div><br></div><div><br></div><div>I've obviously missed something rather fundamental, but the dlang descriptions of each of these attributes are a little light, and leaves me quite unclear on the details here.</div>
<div><br></div><div>I'm particularly confused that I CAN alias a static member in a struct, which I suspect should be TLS for thread safety, but I CAN'T alias a __gshared at global scope, which is not TLS by definition?</div>
<div><br></div><div>O_o</div>
</div>