What would break if class was merged with struct

Stanislav Blinov via Digitalmars-d digitalmars-d at puremagic.com
Sat May 27 11:06:11 PDT 2017


On Saturday, 27 May 2017 at 17:30:49 UTC, Ola Fosheim Grøstad 
wrote:
> On Saturday, 27 May 2017 at 17:22:02 UTC, Stanislav Blinov 
> wrote:
>> But they are incompatible precisely because structs "don't 
>> have it". Inheritance for one. Reference semantics for 
>> another. A class reference is a pointer in disguise, struct is 
>> full layout on the stack. The only way to retain inheritance 
>> and reference semantics while removing "class" keyword would 
>> be not to merge classes into structs, but structs into 
>> classes. And then what, always allocate on the heap?
>
> I don't understand this argument, why would this be more 
> difficult for D than C++?

Perhaps it wouldn't be if we were talking about new language.
With D, such a change falls out of "some language changes, a bit 
of automated source updating and a little bit of breakage", and 
becomes "whole language change, a rewrite of runtime and standard 
library, and breaking every single project that uses D today".
Or did we leave behind your original question?

>> Which is all possible as a library with zero language changes. 
>> But for that to work, classes shall remain classes and structs 
>> shall remain structs.
>
> Huh?

Yes.

>> If that were true, we wouldn't even need the "extern(C++)", 
>> would we?
>
> Sounds more like an implementation detail to me.

:) Everything is an "implementation detail".


More information about the Digitalmars-d mailing list