Classes in D with betterC
Stanislav Blinov
stanislav.blinov at gmail.com
Mon Nov 22 03:36:54 UTC 2021
On Sunday, 21 November 2021 at 20:30:51 UTC, Luís Ferreira wrote:
> I decided to have a simple approach just to show that it is
> easier now to do that without workarounds, and by workarounds,
> I mean using scope to fetch that info and use a fake dtor, or
> even before scope exists, the usage of runtime-less D call with
> betterC + objcopy, described
> [here](https://theartofmachinery.com/2018/05/27/cpp_classes_in_betterc. html).
I get that the news part is all about `__traits(initSymbol)`,
which in this case is about instantiating a class without
druntime.
But that's just one line in the whole example. And the rest of
the code? Construction may either fail altogether or cause
unnecessary copies. Calling __dtor won't call destructors of base
classes or derived classes. There may not even be a __dtor yet
destruction may still be required through __xdtor, which still
would not destruct base or derived classes. Deallocation can't be
@trusted since you don't have a facility to prove that no other
references exist. If anything, the code shows how NOT to use
classes, contrary to what your title or preface say ;)
Even simple, an example should at least be correct, don't you
think?
More information about the Digitalmars-d-announce
mailing list