From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5af5c381381ac5a7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news3.google.com!feeder.news-service.com!feeds.phibee-telecom.net!aotearoa.belnet.be!news.belnet.be!news.net.uni-c.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Newsgroups: comp.lang.ada Subject: Re: Ada requires too much typing! References: Date: Mon, 07 Jun 2010 11:25:46 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Martin Krischik" Organization: Martin Krischik, Softwareentwicklung Message-ID: User-Agent: Opera Mail/10.53 (MacIntel) NNTP-Posting-Host: 89.236.175.138 X-Trace: news.sunsite.dk DXC=R6]Fn0:E;PW5dE91CT5^XYYSB=nbEKnk[O^G9;m`9]d_IDiY_4:UK?Sd3Nai^>E:QM5T2e^5VLiC>9V3IcRFZPT63Q X-Complaints-To: staff@sunsite.dk Xref: g2news1.google.com comp.lang.ada:11396 Date: 2010-06-07T11:25:46+02:00 List-Id: Am 07.06.2010, 10:34 Uhr, schrieb Maciej Sobczak : > On 6 Cze, 14:04, "Martin Krischik" > wrote: > >> > I suppose there must be some cost to doing this? or the language >> > definition would require it to be always so. >> >> Yes indeed, you have virtual dispatch not only on the methods but on >> the instance variables as well. > > No, such concept does not even make sense - instance variables > themselves have no behavior and therefore cannot be "overriden". With > virtual inheritance there is only one copy of the given instance > variable within the whole object, so even the word "dispatch" cannot > be applied there, as "dispatch" relates to "choice" and there is no > choice. > >> Main problem with multiple inheritance was in C++ itself where default >> is “fast” not ”save”. > > No. Neither of these (non-virtual vs. virtual) is "fast" or "safe" in > itself. There is a difference between x.y and x->y. I don't care - but the CPU cycle counters who designed C++ did. > Considering the performance aspect, the layout of variables within the > object is determined *statically* (I have already explained that there > is no "dispatch" involved), which means that there is no run-time cost > in finding the given data item. All instance variables have some > offset from the "beginning" of the object and that offset is computed > statically, whether inheritance is virtual or not. There is no > particular reason for any performance difference in data access, so it > does not make any sense to say than one mode is "fast", while the > other is not. Both are "fast" (it's C++, remember? ;-) ). Interesting opinion. Say we have (all lines in different compilation units, so no fancy optimizer tricks): class Parent {public: int x}; class Child1: public virtual Parent; class Child2 : public virtual Parent; class Incest : public virtual Child1, public virtual Child2; auto Incest* incest = new Incest(); auto Child1* child1 = static_cast (incest); auto Child2* child2 = static_cast (incest); So now tell me how the compiler staticly determines: child1->x; child2->x; As a hint, at any time you could do a: child1=new Child1(); child2=new Child2(); as well. > Considering the safety aspect, the choice between non-virtual and > virtual is design-dependent. >> but main problem stay: not enough C++ programmer have known about >> virtual inheritance > > Again, that knowledge would not necessarily help them, as the use of > virtual inheritance is not automatically justified. Like the use if virtual destructors is not automaticly justified? Only: count in your source the amount virtual destructors vs. non virtual destructors. Why is what you need most not default? In my C++ time the ratio between virtual and non virtual inheritance was similar - and it served me well. >> The real lesson learned: “doing it right” must be default > > Both ways are right. The default one is consistent with the overall > object model. > >> and “make it fast” must be an optional extra > > Both are fast. As I said fast enough for me. Martin -- Martin Krischik mailto://krischik@users.sourceforge.net https://sourceforge.net/users/krischik