immutable, static, __gshared, TLS, and compile time allocation

bearophile bearophileHUGS at lycos.com
Fri Apr 20 15:05:01 PDT 2012


Jonathan M Davis:

> http://d.puremagic.com/issues/show_bug.cgi?id=3934
>
> Whether that'll change or not, I don't know, since it's not 
> clear that Walter considers it to be a problem from what I
> recall about his comments on discussions on it.

It's a significant problem because:
1) It's a _ridiculous_ situation. Allowing some of those things 
I've reported in bug 3934 is bad PR for D language. The DMD 
compiler looks incredibly sloppy compared to every other language 
compiler/interpreter, including old C compilers. It's about at 
7.5 Mega KermitFrog sloppiness, that's almost PHP-level sloppy.
2) It makes much harder for D newbies to learn what's correct and 
what's not correct. When you are learning something new, you 
really want a strict teacher, otherwise you will have a much 
harder time learning what's correct (I've experimentally seen 
that even the total frienshipping inside D modules makes less 
easy to learn the usage of private/protected tags for new OOP D 
programmers).
3) It's confusing even for not newbie programmers, as Manu shows. 
And confusion is bad, error prone, makes people waste time, etc.
4) Different D compilers will be sloppy in slightly different 
ways, this means D code will not be portable across different 
compilers.


>> struct S
>> {
>> static x;
>> __gshared y;
>> }
>> 
>> What is the difference between x and y here?
>
> x is in TLS, so there's one instance per thread. I'm not quite 
> sure whether
> __gshared does anything here though, since it's a member 
> variable rather than
> a class variable or module-level variable. I expect that 
> __gshared is ignored
> here, but I don't know.

I expect __gshared to not be ignored here. I think "__gshared" 
there is the same thing as "__gshared static".

Bye,
bearophile


More information about the Digitalmars-d mailing list