On Thu, 27 May 2010 18:41:19 -0400, bearophile <bearophileh...@lycos.com>
wrote:
Thank you Steven for your explanations, I have done similar things in C
and D, but I didn't understand what you meant.
A is always put first, that way, a pointer to a B can always be used as
a pointer to an A.<
Are you sure C specs say doing this leads to defined behaviour?
(Recently from a discussion with Walter I have learnt that D follows
exactly C specs regarding such defined/undefined things.)
Xt and the Berkeley sockets library relies on it. If it's not in the
spec, then it's a de-facto standard. I think the defined behavior is that
the first member of a struct is positioned at the same address as the
struct itself.
What I would like is a common-sense approach to inheritance for structs
that just does not allow virtual methods or interfaces, and which does
not
cast implicitly to the base (explicit cast is OK). I think some designs
would benefit greatly from this simple feature. I think it's more
tricky
than I've described, but I think with some diligence it can be done.
I have desired some form of inheritance in D structs (before the
creation of alias this, that so far I have not used much). I think
Walter will not love this idea, but you can think more about its
details, and then you can post it in the main D newsgroup.
Sadly, I think it is not much more than a wish. I don't think Walter's
mind can be changed on this.
-Steve