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!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.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: How to get Ada to ?cross the chasm?? Date: Fri, 11 May 2018 16:45:06 -0500 Organization: JSA Research & Innovation Message-ID: References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com> <87in88m43h.fsf@nightsong.com> <87efiuope8.fsf@nightsong.com> <87lgd1heva.fsf@nightsong.com> <87zi1gz3kl.fsf@nightsong.com> <878t8x7k1j.fsf@nightsong.com> <87fu342q1o.fsf@nightsong.com> <87mux9645j.fsf@nightsong.com> <8736yz18e4.fsf@nightsong.com> <87mux62it0.fsf@nightsong.com> <87k1sat1ie.fsf@nightsong.com> Injection-Date: Fri, 11 May 2018 21:45:07 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="28724"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:52296 Date: 2018-05-11T16:45:06-05:00 List-Id: "Niklas Holsti" wrote in message news:flmdbnFbrgaU1@mid.individual.net... > On 18-05-11 22:50 , Paul Rubin wrote: >> Niklas Holsti writes: > >>> If one uses specific array index types, as good Ada style requires, an >>> Ada compiler can trivially omit many array bounds checks for which a >>> bounds-checking C compiler would have to use a global data-flow >> >> If you mean the index is in an int range type, then the Ada compiler >> should have to make a range check every time you modify the index, >> unless it can statically prove that the new value is in range. > > Yes, but often the compiler can do that. > >> So you've just moved the check from one place to another. > > Sometimes that is so. But sometimes the value is used in many places, or > frequently, and modified in one place, or rarely, so the number of checks > is reduced, in the static and/or dynamic measure. Also note that in the common special case of loop iteration, no checks are needed at all, either at the generation of the index or it's use: for I in Arr'Range loop ... Arr(I) ... end loop; I cannot be outside of it's range by construction, so no checks needed there other than the usual loop termination check, and that being the case, no checks are needed on the array indexing, either. For many of the Ada checks, the existence of a check that can fail indicates poorly written Ada code and/or a potential bug. I'm working toward having the compiler (optionally) identify these during compilation, so that one can improve the code to eliminate the danger *before* testing. Randy.