What would break if class was merged with struct

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


On Saturday, 27 May 2017 at 18:44:42 UTC, Ola Fosheim Grøstad 
wrote:
> On Saturday, 27 May 2017 at 18:44:03 UTC, Stanislav Blinov 
> wrote:
>> On Saturday, 27 May 2017 at 18:13:52 UTC, Ola Fosheim Grøstad 
>> wrote:
>>
>>>> Or did we leave behind your original question?
>>>
>>> No. I am talking about language semantics. Are the semantics 
>>> for class and struct conflicting or can they be merged?
>>>
>>> That is the question.
>>>
>>> I am talking about the language, as specified, not the 
>>> implementation.
>>
>> Ahem. As specified, classes are reference types, struct 
>> aren't. What more is there to say?
>
> Structs are reference types too. The specification is wrong.

I've seen this argument from you before, and it's incorrect. 
Structs may adopt reference semantics if they aggregate pointers, 
that's true. But they are not themselves reference types. Their 
representation is laid out inline. Classes, OTOH, are always 
references, to get at their memory you need an indirection. Thus, 
if we were to merge classes and structs, we'd have to pick one or 
the other.


More information about the Digitalmars-d mailing list