Article: Alternatives to C++
tsbockman
thomas.bockman at gmail.com
Mon Mar 8 21:41:48 UTC 2021
On Monday, 8 March 2021 at 21:00:47 UTC, Ali Çehreli wrote:
> My only regret is the space cost of the monitor pointer of all
> D class objects. So, I hereby help populatize something I
> learned recently: extern(C++) class definitions don't have that
> monitor pointer:
>
> // Smaller object:
> extern (C++) class C {
> // ...
> }
I think this critical bug I discovered today needs to be fixed
before that's a good idea: dynamic casts seem to be completely
broken for extern(C++) classes.
https://issues.dlang.org/show_bug.cgi?id=21690
This can manifest as a logic error, memory corruption, or a
security vulnerability depending on the circumstances.
More mundanely, extern(C++) mangling can't distinguish some
overloads that extern(D) can. Thankfully, this problem can be
worked around in an easy (albeit ugly) way:
extern(C++) class C { extern(D):
// ...
}
In particular, I found the above necessary to enable overloading
on `shared` with extern(C++) class methods.
More information about the Digitalmars-d
mailing list