__traits(vptr) returns the vptr, but there's no size information so the vtbl is not availale. There should be a trait for that.
This blocks https://github.com/dlang/druntime/pull/3174.
Comment #1 by bugzilla — 2020-08-10T21:13:58Z
It's actually not a __trait, is a pseudo-member:
class C { ... }
void test(C c)
{
c.vptr // not the vtbl[] for C, but for the derived class that c is
}
What I can do is make:
C.vptr give a pointer to the vtbl for class C
I don't think your use actually needs to know the number of entries in it?
Comment #2 by destructionator — 2020-08-10T21:26:09Z
Number of entries might be useful though, can't the compiler just issue a void*[] when asked instead of a void**?
The object instance might only be void** since the length I don't think is actually stored and that's a dynamic object, plus backward compatibility abi etc. But for the static type the compiler knows so it can tell at no additional cost.
Comment #3 by andrei — 2020-08-11T20:14:30Z
(In reply to Walter Bright from comment #1)
> It's actually not a __trait, is a pseudo-member:
>
> class C { ... }
> void test(C c)
> {
> c.vptr // not the vtbl[] for C, but for the derived class that c is
> }
My bad.
> What I can do is make:
>
> C.vptr give a pointer to the vtbl for class C
>
> I don't think your use actually needs to know the number of entries in it?
I think the number of entries is important for applications that want to stick their own type-specific info at the end of the table. Those could copy the vtbl to the GC heap and append to it.
Comment #4 by andrei — 2020-08-11T20:16:03Z
Better yet, the vtbl would be NULL-terminated. That allows multiple applications to add to it without stepping on each other's toes.
Comment #5 by robert.schadek — 2024-12-13T19:10:48Z