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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 12 13:33:31 PST 2010


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

           Summary: Built-in __vptr attribute for classes too
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-03-12 13:33:25 PST ---
The attribute __vptr of object instances can be useful in some special
situations. To compare the __vptr of an object instance to the __vptr of a
class you first need to find the __vptr of a class. You can do it with code
similar to:


class Foo {
    __gshared static immutable(immutable(void)*) __vptr;
    static this() {
        scope auto aux = new typeof(this);
        __vptr = aux.__vptr;
    }
    //...
}
void main() {}


But this is not handy (even if a class mixin can help). So a built-in __vptr
attribute can be added to classes too.

Possible disadvantages: the need for __vptr is rare.

-------------

Note: there are other ways to implement virtual functions, like using a
dispatch tree, so the D docs can say that __vptr can be absent in D compilers
that don't use a virtual table or in other situations.

-- 
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