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,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) Date: 21 Mar 2005 16:00:23 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1lr611thktbau$.1dj95z21h7l5v.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1111438824 11356 192.74.137.71 (21 Mar 2005 21:00:24 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 21 Mar 2005 21:00:24 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:9692 comp.lang.c++:46604 comp.realtime:1572 comp.software-eng:5174 Date: 2005-03-21T16:00:23-05:00 List-Id: azdo_b@yahoo.es (Alberto) writes: > "Dmitry A. Kazakov" wrote in message news:<1lr611thktbau$.1dj95z21h7l5v.dlg@40tude.net>... > > But even then bounds checking is not needed for every access. Example: > > > > procedure Dynamic (A : Some_Array) is > > subtype Index is Array_Index range A'Range; > > J : Index := A'First; > > > > for I in A'Range loop > > A (I) := .. -- No checks > > ... > > J := I; > > end loop; > > A (J) := ... -- Still no checks > > > > C++ completely lacks the notion of constrained subtypes which makes the > > above possible. > > If Some_Array is any array supplied at run-time, how can the compiler > know what values are stored in A'Range? (I mean, what the bounds of > the array are) It *has* to check these bounds at run-time. No, that's not correct. Some compilers can and do prove that I is within the bounds of A, and therefore avoid generating any checking code. Neither the array bounds, nor the value of I, need be known at compile time. In general, if *you* can prove something about a program, then it is possible to teach a compiler to do so. Not necessarily *feasible*, but *possible*. This is related to what Appel calls the "full employment act for compiler writers" or some such -- no matter how smart a compiler is, it's always possible to write a smarter one. But in the above code, it is both possible and feasible to eliminate *all* of the bounds checking. Thus, there's no need to suppress checks on the above code. > > 2. C++ is unable to allocate objects of indefinite size on the stack. > > Well, we have alloca() for this ;) Is alloca part of the C++ standard? I thought not, but I could be wrong. Anyway, alloca doesn't really do all that Ada can do in this regard (avoiding heap usage for dynamic-sized things). In this case, the Ada feature is both more efficient and safer than alloca. - Bob