Can we just have struct inheritence already?

Nick Sabalausky (Abscissa) SeeWebsiteToContactMe at semitwist.com
Wed Jun 12 04:31:24 UTC 2019


On 6/10/19 7:00 PM, H. S. Teoh wrote:
> On Mon, Jun 10, 2019 at 06:35:16PM -0400, Nick Sabalausky (Abscissa) via Digitalmars-d wrote:
>>
>> Would it really be a problem for the addresses of zero-byte structs to
>> just simply be null?
> 
> Probably, if people expect:
> 
> 	struct S {}
> 	S s;
> 	assert(&s !is null);
> 
> to work.

Ehh, maybe, but since when does anyone ever check a D struct's address 
for being null?

Even if you DID have a struct who's address was null (due to being zero 
size), then unlike for classes, using the struct's methods or static 
members would still be no problem since it wouldn't involve 
dereferencing the null (Instead, for the static members it's irrelevent 
entirely, and for the rest: it would just simply pass null as the hidden 
argument to member functions which - outside of @system pointer 
manipulation - would still have no way to actually dereference the null, 
because there's no non-static data members to even refer to, let alone 
access.)

Or, heck, even just have it share an address with another data member. 
That or the null thing, I see no realistic problem either way. Or if you 
really want to be needlessly clumsy about it, have an attribute or 
pragma or something that says "If this field is a zero-byte struct, then 
for the love of god make it zero byte, I don't even care how you do it."

I really don't like the whole "ships have sailed" theme in D though. It 
just gives a straight up middle finger to "The Last Thing D Needs" and 
to the whole reason for D's creation in the first place - to fix stupid 
legacy mistakes.

And yea, sure, of course we have bigger fish to fry. But that should 
never be a reason to say "The mistake is realistically fixable, but NO, 
never gonna anyway!" instead of "Right, that was a mistake and it's 
fixable. We should fix it sooner or later BUT it's not a high priority 
right now."


More information about the Digitalmars-d mailing list