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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,68eb48aa63fb3f1d,start X-Google-Attributes: gid103376,public From: Valentin Bonnard Subject: Re: C vs Ada code quality Date: 1997/05/01 Message-ID: <3367C474.6ABA@pratique.fr>#1/1 X-Deja-AN: 238506798 To: Robert Dewar Organization: Internet Way Reply-To: bonnardv@pratique.fr Newsgroups: comp.lang.ada Date: 1997-05-01T00:00:00+00:00 List-Id: Robert Dewar writes: > < is imcomplete since C++ rely on overloading (compile time) > and Ada on overiding (run time).>> > > Right, you are not a specialist in Ada, and your guesses are wrong. I will > say this again, quite clearly this time I hope: The controlled types in > Ada are exactly equivalent to the destructors in C++. I don't understand how this can be. > They involve > dispatching only when it would also be neessary in C++. I don't know what > leads to your misconceptions here, but they are misconceptions. The fact that I believe that : - tagged types can be used polymorphically thus have the vtable pointer even if they aren't use polymorphically - functions on tagged type are 'virtual', that is, they are called based on the dynamic type > Probably you are confusing the formal description with the implementation. > The fact that controlled types in Ada are derived from controlled does > not mean you have to implement them any differently from C++. Yes I assume they are implemented the same: class Controled { public: Controled (); // I don't how to write operator= here virtual ~Controled () = 0 { } // if this syntax is allowed in C++, I'm not sure }; This means that there is a runtime penatly in general for class derived from Controled (very localised and pretty small actually). > <> > > yes,yes,yes you *are* comparing a particular implementation. You just don't > realize what the distinction is between what is required in the semantics > and what a typical implementation uses to provide these semantics. I am not; you are off base (or you want me to believe that). Can you for example tell me an implementation which doesn't use a vtable ? (Of course details of the representation of the vtable can change a little.) Perhaps you know at special debugging implementation which doesn't use the vtable, but I'm talking about real compilers, not interpretors. > In both Ada and C++, finalization (destructors) are defined on individual > types, and have to be called at the right time. End of story, no significant > difference! Now you may wonder why in practice C++ implementations have > avoided the use of dynamic lists for finalization, and Ada implementations > have often used them. The answer is simple. Once you have to deal with > exceptions the dynamic list has real advantages -- the C++ world is > working through these problems now -- for example, see the discussions > with respect to g++ and exeptions, where recently someone seriously > suggested the possibility of going to lists for handling destructors. EH should be done with global walkback table; only the most basic implementation register the objects (the first implementation of EH in the first release that support it). Modern EH doesn't slow down code that doesn't throw (or should I write raise, since we are in c.l.a ?); the other method, singnificatly easier to implement is that all object register and de-register all the time; this has an awfull abstraction penalty. (Assuming exceptions are exceptionnals, which is true in real code in C++, but it is in Ada ?) > < help ? Does this keyword serve any purpose (the compiler can > look at the source to see if you are taking accesses to a > variable directly) ? Is it like the register keyword in C (ie > the semantic of a register variable is the same but you can't > take its address) ?>> > > Of course not! You are forgetting separate compilation -- the same problem > of course arises in C. Yes, you can sometimes tell for local variables > (e.g. in the absence of subunits), but in C and C++ global variables > have to be assumed to be aliased, and this is not the case in Ada. Ok, but for more flexible interfaces, shouldn't you declare everything aliased ? Is Ada lower level than C/C++ in this respect (C++ programmers consider that the fact a variable is aliased is a low level detail) ? (While Ada operates at a clearly higher level than C/C++ wrt arg passing (IN/OUT vs T, T&, const T&, T*, const T* types).) -- Valentin Bonnard mailto:bonnardv@pratique.fr http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)