Can we just have struct inheritence already?
aliak
something at something.com
Thu Jun 13 10:25:02 UTC 2019
On Thursday, 13 June 2019 at 09:44:12 UTC, Vladimir Panteleev
wrote:
> On Thursday, 13 June 2019 at 05:31:23 UTC, Walter Bright wrote:
>> On 6/11/2019 3:02 AM, Vladimir Panteleev wrote:
>>> [...]
>>
>> Ok, you got me there.
>>
>> Here's what Stroustrup says:
>>
>> http://www.stroustrup.com/bs_faq2.html#sizeof-empty
>
> From the page:
>
> Empty a, b;
> if (&a == &b) cout << "impossible: report error to compiler
> supplier";
>
> However, no further justification is provided why that is a
> problem.
>
> Perhaps it's something the C++ spec was written to guarantee,
> but does not apply to D?
Just for amusement, rust has ZSTs (zero sized types) and Empty
types (they distinguish between the two) -
https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts
And here's a consequence of that:
https://github.com/rust-lang/rust/blob/e011fe1c132010e261cc9ea658da73152f1f7fc7/src/liballoc/vec.rs#L2428
Here's a more detailed "beware of these guys"
https://gankro.github.io/blah/only-in-rust/#honorable-mention-zero-sized-types-zsts
"However, in low level (unsafe) code zero-sized types can be a
bit hazardous, for two reasons:
If you try to malloc some number of zero-sized types naively,
you'll pass an allocation size of 0 to the allocator, which is
implementation-defined at best. Also you want to avoid allocating
these things anyway!
If you try to offset a pointer to a zero-sized type naively, you
will get nowhere. This breaks a C-style "two pointers moving
towards each other" iterator."
Swift and go are also mentioned in the above link.
Cheers,
- Ali
More information about the Digitalmars-d
mailing list