What would break if class was merged with struct
Moritz Maxeiner via Digitalmars-d
digitalmars-d at puremagic.com
Sat May 27 13:24:26 PDT 2017
On Saturday, 27 May 2017 at 19:26:50 UTC, Ola Fosheim Grøstad
wrote:
> On Saturday, 27 May 2017 at 19:01:12 UTC, Moritz Maxeiner wrote:
>> Here, `bar`, takes a (pointer to a) class instance as
>> parameter `foo`. `foo` is a single pointer, i.e. 8 bytes on a
>> 64bit OS, with *no* special semantics.
>
> Does the language spec say anything about the size of class
> references?
Yes, is is defined as `ptrsize` and must have the exact same size
as a pointer to a struct and - more importantly - a pointer to a
stack frame[1].
>
>> If you want a smart pointer, use one, but don't suddenly make
>> something that isn't a smart pointer by language design change
>> shape into a smart pointer.
>
> Is it specified?
Yes, see above link. Unless you make *all* stack frame pointers
smart pointers (which makes no sense whatsoever), class instances
cannot be smart pointers in the language as it is specified right
now.
>
> The common implementation uses a GC, but does it say that an
> implementation cannot use a reference counted smart pointer or
> a fat pointer instead?
>
>> Sure, but then type `Foo` in the above must remain a normal
>> pointer, not become a smart pointer.
>
> That really depends on the definition of the language.
Sure, and the definition requires it.
[1] https://dlang.org/spec/abi.html#delegates
More information about the Digitalmars-d
mailing list