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,ab1d177a5a26577d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!o10g2000vbg.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: What's wrong with C++? Date: Thu, 17 Feb 2011 03:51:14 -0800 (PST) Organization: http://groups.google.com Message-ID: <41466bc1-dd61-4160-b737-40c9c2ddb2c9@o10g2000vbg.googlegroups.com> References: <1ee1a434-4048-48f6-9f5e-d8126bebb808@r19g2000prm.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297943474 30935 127.0.0.1 (17 Feb 2011 11:51:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 17 Feb 2011 11:51:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o10g2000vbg.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012111 Red Hat/3.0.6-1.el5 Firefox/3.0.6,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:18302 Date: 2011-02-17T03:51:14-08:00 List-Id: KK6GM wrote on comp.lang.ada: > This is a serious question, seeking objective information. =A0I've > worked with C for many years and I have a very good understanding of > its weaknesses, which are many. =A0I haven't done nearly so much C++, > and what I have done was not very intensive (didn't use a great many C+ > + features), so I don't have a good understanding of its weaknesses. > > So, without turning into a bash-fest, what are some general-consensus > weaknesses or failures or problems with C++? =A0Comparisons with Ada are > welcome but not required. =A0And my focus is in the embedded & real-time > arenas, FWIW. The keyword "virtual". If you forget it, you get static dispatching instead of dynamic dispatching and the compiler cannot tell you whether that's right or wrong. In Ada, any primitive operation of a tagged type is implicitly and automatically "virtual", so you can't forget the keyword. In C++, one particular case of this language flaw is that you can forget to make your destructors virtual; good luck debugging that later. In C++, looking at the spec of a derived class, you can't tell which methods are virtual (because they override an inherited virtual method) and which are not. You have to look at all the ancestor classes to know. In Ada, you can tell immediately without looking up any ancestor types. In C++, looking at a method call, you can't tell whether it dispatches statically (non-virtual method) or dynamically (virtual method); you must look it up in the declaration of the class *and* all its ancestors. In Ada, you can tell immediately: a call dispatches statically if the actual parameter is of a specific type, and dynamically if of a class-wide type. In C++, you are required to use pointers or references to objects to achieve dynamic dispatching. This is wrong. Pointers and references should only be used for dynamic memory management and links between objects, just like they are in Ada. I find the following quite confusing: class C { virtual void foo(); }; C c; c.foo(); // static dispatch (&c)->foo(); // dynamic dispatch The reason for this is that, in C++, all (implicitly declared) pointer and reference types are (implicitly and always) class-wide, so always dispatch dynamically; in contrast, objects are always of a specific type, so cannot dispatch dynamically. In Ada, the two concepts are orthogonal; access types can be either specific or class-wide, and types of objects can also be specific or class-wide. -- Ludovic Brenta.