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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 24 18:27:57 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3939



--- Comment #1 from bearophile_hugs at 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_staticCtor1FZv    comdat
        mov    EAX,_D4test3Foo7__ClassZ[0Ch]
        mov    ECX,[EAX]
        mov    _D4test3Foo7classIdyk,ECX
        ret

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


More information about the Digitalmars-d-bugs mailing list