immutable, static, __gshared, TLS, and compile time allocation
Michel Fortin
michel.fortin at michelf.com
Fri Apr 20 18:41:07 PDT 2012
On 2012-04-21 00:22:21 +0000, Manu <turkeyman at gmail.com> said:
> On 21 April 2012 03:05, Michel Fortin <michel.fortin at michelf.com> wrote:
>
>> If you're trying to make a C-like global, write this:
>>
>> static __gshared int x;
>
> dlang.org seems to disagree:
> "__gshared may also be applied to member variables and local variables. In
> these cases, *__gshared is equivalent to static*, except that the variable
> is shared by all threads rather than being thread local."
> Suggests to me that you are not required to state both.
I don't really think this is incompatible. __gshared wouldn't make
sense for local and member variables, so it makes sense that it sort of
implies static. I just didn't know it was implied (and thus redundant).
> So which is correct?
> It appears most people are confused about this. I'm thinking more and more
> it's worth addressing that confusion with some warnings/errors.
I'm not sure what the problem is. If I see __gshared attached to a
variable declaration, it means it behaves like a C global. If you don't
need to specify "static" explicitly when inside a scope that can have
member variables, then great: it's not like non-static __gshared makes
sense anyway.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list