What would break if class was merged with struct
Stanislav Blinov via Digitalmars-d
digitalmars-d at puremagic.com
Sat May 27 09:52:17 PDT 2017
On Saturday, 27 May 2017 at 16:37:04 UTC, Ola Fosheim Grøstad
wrote:
> On Saturday, 27 May 2017 at 16:31:32 UTC, Stanislav Blinov
> wrote:
>> There's a lot more difference in D. Classes in D are fat
>> memory chunks storing pointers to ClassInfo (inc. vtable),
>
> So are classes with virtual functions in C++, to get RTTI you
> need to have a virtual member function. I don't see the big
> difference.
But structs in D have none of that.
>> Monitor (i.e. for "synchronized") and
>
> Wasn't this going to be removed?
Not that I'm aware of.
>> a list of all interfaces they implement,
>
> Semantically roughly the same as multiple-inheritance in C++
> but more limited.
>
>> If we were to remove all that, we'd lose the semi-natural way
>> of interfacing to C++ classes, and some pretty horrendous code
>> involving void* and void** would have to be used.
>
> I don't understand what you mean here.
If your "struct _class_SomeThing" would simply describe the same
memory layout of classes that we have today, then no language
change is necessary, it's purely a library solution. Well...
maybe we'd need to add class postblits if we wanted copying
(which can also be done by hand with a library "clone" function
and a "special" static __postblit function).
If not, then it gets complicated, as in order to retain an
interface with C++ classes, D would either have to follow C++ ABI
(he-he), or at the very least put the burden of mapping member
function calls on the programmer.
More information about the Digitalmars-d
mailing list