Why no offsetof for static struct?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 10 13:13:46 PDT 2017
On Monday, 10 July 2017 at 20:01:39 UTC, FoxyBrown wrote:
> Cannot get the offset of static members of a struct
That's because static members do not have an offset. They are not
part of the struct in memory, just in name.
> We can clearly get a pointer to the static struct X
There's barely any such thing as a static struct. That's just a
struct that stands without outside context.... which is almost
all structs, actually, so the term isn't special.
> since &X.x is effectively the address of X(regardless
> nomenclature and terminology issues in D trying to hide this).
No, it isn't. Static members are stored in an entirely different
place than non-static members. They are really just global
variables in memory with their in-source name being nested
somewhere else.
More information about the Digitalmars-d-learn
mailing list