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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada Annoyances Date: Sun, 25 Jun 2017 19:06:24 -0500 Organization: JSA Research & Innovation Message-ID: References: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <1498048151.20885.28.camel@obry.net> <96174ea5-852d-44e9-8535-7c1eb24d5326@googlegroups.com> <8d3aff06-82df-485f-89e5-a50c326aab05@googlegroups.com> <66aa262e-2ac9-4016-b32d-e9fee14779e1@googlegroups.com> <88e2f18a-0786-4303-a5b8-fe82e8c81dcb@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1498435585 26042 24.196.82.226 (26 Jun 2017 00:06:25 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 26 Jun 2017 00:06:25 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:47116 Date: 2017-06-25T19:06:24-05:00 List-Id: "Maciej Sobczak" wrote in message news:bb2dce33-54bd-426c-9029-f965fa007e3b@googlegroups.com... ... > In C++ when the object of derived class is constructed, its base class > constructor is called first and at that time the object is considered to > have > the Base dynamic type, which makes sense, as the derived parts have not > yet been initialized (they will be initialized in the Derived constructor, > which > will happen later). Only after the base constructor finishes, the dynamic > type > of the object is "promoted" to Derived. This means that virtual calls > within > the Base constructor will never dispatch to Derived variants, which is > safer, > as it prevents accidental access to not-yet-initialized parts of the > object from > virtual functions. We say that from within constructors (and destructors, > where the same process goes in the reverse direction) the static type is > equal to the dynamic type of the object. > Ada does not have this feature and diaptching calls can access > uninitialized > components from derived parts by means of dispatching to the not-yet-born > parts of the object. C++ needs this model since it has no way to eliminate dispatching from routines. In Ada, where redispatching requires explicit work, the vast majority of constructors will never make a dispatching call so there is very little risk. The problem in Ada is that there isn't any way to determine which routines are used as constructors (they're just ordinary routines), so it isn't possible to enforce special rules on them. And banning all redispatching seems too draconian. In any case, this problem is irrelevant. Since it is, in general, impossible for the language to determine a safe order of initialization for the components of an arbitrary record type (3.3.1 has a complicated set of rules attempting to do that, but it is known not to work in all cases, and it's unlikely that they're consistently implemented, either), there are much worse problems that can be caused by a clueless type constructor (which would apply to almost all of us). Ada at least tries to define the order of initialization (that is, elaboration). Most other languages don't even try. The net takeaway is that a truly type-safe language maybe could be constructed, but it would have to be an incredibly simple language with very little practical application. So that sort of thing is irrelevant. Randy.