What would break if class was merged with struct

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Sat May 27 12:10:15 PDT 2017


On Saturday, 27 May 2017 at 18:56:47 UTC, Stanislav Blinov wrote:
> 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.

This is the ACID test: Values have no identity. An instance of a 
struct has an identity.

Allocation is another issue. A stack allocation is just an 
optimization of a heap allocation. Many languages put all the 
activation records (stack frames) on the heap. This is very 
useful for high levels of concurrency.

> 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.

Structs are more general, so you don't have to pick anything, you 
just add the class features to the struct.

That means the minimal core language no longer have the class 
concept.

The full language with lowering (syntactical sugar) still has the 
class concept since it can be covered by struct + "smart pointer" 
+ modified new.



More information about the Digitalmars-d mailing list