[Issue 3939] Built-in __vptr attribute for classes too

2018-05-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3939

Dmitry Olshansky  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||dmitry.o...@gmail.com
 Resolution|--- |WONTFIX

--- Comment #2 from Dmitry Olshansky  ---
Could be taken from typeinfo, see object.d:

class TypeInfo_Class : TypeInfo
{
...
   void*[] vtbl;   /// virtual function pointer table
   Interface[] interfaces; /// interfaces this class implements
...
}

So I believe those who truly need it will find it. And solution provided is
actually fine for such low-level goal.

--


[Issue 3939] Built-in __vptr attribute for classes too

2010-10-24 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3939



--- Comment #1 from bearophile_h...@eml.cc 2010-10-24 18:27:12 PDT ---
Currently this seems the most efficient way to have a static class attribute
that contains a __vptr (here converted to a size_t and named classId):


class Foo {
static immutable size_t classId;
static this() {
classId = *(cast(size_t*)(typeid(Foo).init.ptr));
}
}
void main() {
assert(cast(size_t)((new Foo).__vptr) == Foo.classId);
}


With it DMD 2.049 generates a very light static constructor:


_D4test3Foo12_staticCtor1FZvcomdat
movEAX,_D4test3Foo7__ClassZ[0Ch]
movECX,[EAX]
mov_D4test3Foo7classIdyk,ECX
ret

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---