Are D classes proper reference types?
kinke
noone at nowhere.com
Sun Jun 27 10:11:44 UTC 2021
On Sunday, 27 June 2021 at 09:46:45 UTC, Ola Fosheim Grøstad
wrote:
> On Sunday, 27 June 2021 at 08:41:27 UTC, kinke wrote:
>> Getting rid of the monitor field was discussed multiple times.
>
> You don't have to get rid of it, just implicitly declare it for
> classes that use monitors? I don't think it has to be at a
> specific offset?
It's not about classes using monitors themselves, it's about
people potentially using `synchronized (obj)` for some arbitrary
class reference `obj`. Embedding it in the instance directly
prevents having to use a hashtable or similar. But I'm certainly
not fond of that field as it's a rare use case.
>> The other major and not so trivial difference is that
>> extern(C++) classes have no TypeInfo pointer (in the first
>> vtable slot for extern(D) classes), which also means that
>> dynamic casts don't work, neither in D nor in C++ (for the
>> latter, only for instances instiantiated on the D side).
>> [AFAIK, most C++ implementations put the - of course totally
>> incompatible - *C++* TypeInfo into vtable slot -1.]
>
> But D could just extend C++ typeinfo?
Sure, 'just' :D - as it 'just' takes someone to implement it (for
all supported C++ runtimes). It's always the same problem, lots
of talk and blabla in the forum, but hardly any real action
coming out of it.
More information about the Digitalmars-d-learn
mailing list