How to get the address of a static struct?
Era Scarecrow via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 9 21:39:44 PDT 2017
On Monday, 10 July 2017 at 03:48:17 UTC, FoxyBrown wrote:
> static struct S
>
> auto s = &S; // ?!?!?! invalid because S is a struct, but...
>
> basically s = S. So S.x = s.x and s.a = S.a;
>
> Why do I have to do this?
Static has a different meaning for struct. More or less it means
it won't have access to a delegate/fat pointer to the function
that uses it. It doesn't mean there's only 1 instantiation ever
(unlike like the static variables). So static is a no-op in this
case (though still syntactically legal to use).
To get the address of the struct you STILL have to instantiate
it first. Although you don't to in order to access it's static
members.
Though if all the members are static, it's basically a namespace
and doing so is kinda pointless.
More information about the Digitalmars-d-learn
mailing list