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

Manu turkeyman at gmail.com
Fri Apr 20 16:38:47 PDT 2012


On 21 April 2012 01:48, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> Please give code examples. I'm much more likely to understand what you mean
> that way.
>

The code in question was in my OP, but that said...


static shouldn't have anything to do with TLS beyond the fact that it
> doesn't
> make any sense for a non-static member variable to be marked as shared or
> __gshared, since whether it's in TLS or not is determined whether the
> object
> that it's in is TLS or not.
>
> In the case of a struct or class, static merely states that there's only
> one
> instance per class/struct rather than it being a member variable, not
> anything
> about TLS. And if the documentation states that the static is implied for
> __gshared (I haven't read it recently), then that that just means that
> __gshared is always static so that you don't get the weird situation where
> you
> have a __gshared member variable (which would be meaningless as far as I
> can
> tell).
>

Okay, I've just done some more tests taking what has been said here.
I realise I wasn't confused to begin with, I've been introducing confusion
into my brain in order to attempt to understand why my test case was
rejected.

I've simplified it, like so:


// member contained in a struct
struct Thing
{
    int x;
}

Thing thing; // this is effectively identical to declaring 'int x;'
globally, it's just wrapped in a thin struct

int x; // i'll also do it directly, to prove it works.

void main()
{
    // these 3 statements should be effectively identical
    thing.x = 0; // this works, obviously
    AliasTheStruct!( thing )(); // this works
    AliasTheInt!( thing.x )();  // this doesn't

    AliasTheInt!( x )();        // of course, this works fine
}

void AliasTheStruct( alias x )()
{
    x.x = 10;
}

void AliasTheInt( alias x )()
{
    x = 10;
}


As far as I can tell, this should work. It doesn't. This was my bug report.
Is this a legitimate bug?
This has hindered a lot of my code for days, cost me a lot of time, and I
see no technical reason why it shouldn't work.

All the __gshared/static business was confusion that was seeded while
trying to understand what Walter meant while rejecting my bug request.
I do clearly understand all that stuff after all ;) .. lets forget I
brought that up, although I think the observation that it is rather
confusing in the first place, and the fact the compiler silently ignores
invalid attributes might be significant. There's probably some room for
improvement there.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120421/18f38f5e/attachment.html>


More information about the Digitalmars-d mailing list