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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,56525db28240414a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.77.199 with SMTP id u7mr3212307paw.25.1343789444370; Tue, 31 Jul 2012 19:50:44 -0700 (PDT) Path: p10ni9631378pbh.1!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nrc-news.nrc.ca!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Efficient Sequential Access to Arrays Date: Thu, 26 Jul 2012 15:46:04 +0200 Organization: cbb software GmbH Message-ID: <1d20andzhb0rk.ytxhpkza8tky$.dlg@40tude.net> References: <01983f1c-f842-4b1f-a180-bcef531dad4c@googlegroups.com> <87ipdf4vh6.fsf@mid.deneb.enyo.de> <4ce44d2d-d789-42a0-a6ed-035f7f8d58be@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: 9A8bJrx4NhDLcSmbrb6AdA.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-07-26T15:46:04+02:00 List-Id: On Thu, 26 Jul 2012 05:32:32 -0700 (PDT), Keean Schupke wrote: > So if I do > > if X'Valid then > Y(X) -- if X is the same type as the index of Y then no need to range check. > end if > > If I explicitly check 'Valid, the compiler should be able to omit some > implicit range checks, as 'Valid is an explicit range check. No. You do it this way: declare subtype Y_Index is Integer range Y'Range; Safe_X : Y_Index := X; begin ... Y (Safe_X) ... -- The compiler has here information to -- eliminate check, though not required to end; P.S. The attribute 'Valid is used when there is a danger that the compiler hasn't checked the argument for whatever reason. Usually it is after Unchecked_Conversion. Some would disagree, but IMO in a well-written Ada program you should never ever need 'Valid. Don't do Unchecked_Conversion with doubtful outcome. Don't use stream attributes for constrained types. Don't use for X'Address use Z'Address for the purpose of conversion etc. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de