Re: Why no offsetof for static struct?

2017-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 11:14 PM, FoxyBrown wrote: auto GetStaticAddress(T)() { mixin("auto p = cast(T*)"~__traits(allMembers, T)[0]~";"); return p; } Returns the address of a struct's static members. No, it returns the address of T's first member. It's pretty obvious, the compiler seems to

Re: Why no offsetof for static struct?

2017-07-10 Thread Mike Parker via Digitalmars-d-learn
On 7/11/2017 6:14 AM, FoxyBrown wrote: On Monday, 10 July 2017 at 20:13:46 UTC, Adam D. Ruppe wrote: 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

Re: Why no offsetof for static struct?

2017-07-10 Thread Ali Çehreli via Digitalmars-d-learn
On 07/10/2017 02:14 PM, FoxyBrown wrote: > On Monday, 10 July 2017 at 20:13:46 UTC, Adam D. Ruppe wrote: >> 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

Re: Why no offsetof for static struct?

2017-07-10 Thread FoxyBrown via Digitalmars-d-learn
On Monday, 10 July 2017 at 20:13:46 UTC, Adam D. Ruppe wrote: 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

Why no offsetof for static struct?

2017-07-10 Thread FoxyBrown via Digitalmars-d-learn
Cannot get the offset of static members of a struct struct X { __gshared public: int x; } X.x.offsetof < invalid. We can clearly get a pointer to the static struct X since is effectively the address of X(regardless nomenclature and terminology issues in D trying to hide this).

Re: Why no offsetof for static struct?

2017-07-10 Thread Adam D. Ruppe via Digitalmars-d-learn
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

Why no offsetof for static struct?

2017-07-10 Thread FoxyBrown via Digitalmars-d-learn
Cannot get the offset of static members of a struct struct X { __gshared public: int x; } X.x.offsetof < invalid. We can clearly get a pointer to the static struct X since is effectively the address of X(regardless nomenclature and terminology issues in D trying to hide this).