Are D classes proper reference types?

kinke noone at nowhere.com
Sun Jun 27 08:41:27 UTC 2021


On Sunday, 27 June 2021 at 07:54:38 UTC, Ola Fosheim Grøstad 
wrote:
> That is all good, but it will lead to `extern(C++) class` 
> replacing D classes. So why not unify right away? Why wait for 
> the inevitable?

The assumption that all D code and all classes therein are or 
need to be designed for C++ interop is daring. The DMD frontend 
uses extern(C++) classes almost exclusively, but that's just for 
LDC and GDC.

Getting rid of the monitor field was discussed multiple times. 
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.]


More information about the Digitalmars-d-learn mailing list