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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,df40d0d1975a16a6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-13 07:43:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!213.200.246.247!not-for-mail From: Vinzent Hoefler Newsgroups: comp.lang.ada Subject: Re: Optimizing Boundary Checks Date: Fri, 13 Jun 2003 16:42:14 +0200 Organization: JeLlyFish software Message-ID: References: <20030613140324.0000372e._elh_@_terma_._com_> NNTP-Posting-Host: 213.200.246.247 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: fu-berlin.de 1055515423 19048931 213.200.246.247 (16 [175126]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:39121 Date: 2003-06-13T16:42:14+02:00 List-Id: Preben Randhol wrote: >So to sum up: > >If I had done: > > subtype Index_Range is Integer range 1 .. 10; > type Items is array (Index_Range) of Natural; > > Boxes : Items; > Index : Integer :=3D 11; >begin > > Boxes (Index) :=3D 1; > >then I get an constraint error at run-time as the compiler will accept >the code. Yes. >And in this case range checks on the array must be on. Of course. Well, I think there's a catch: it could be possible that even with range checks turned off, you *could* get an exception here, for instance if the optimizer can already boil the code down that far. Suppressing checks doesn't mean you will never get an exception at runtime, see the note in RM 11.5(29). >If I >change to: > > type Index_Range is range 1 .. 10; > >Then the range checks on the array *can* be switched off as the range >checks of Index_Range will do. > >Is this right? Yes, perfectly. >I'm asking because there was an post some days ago saying that my >example above could have range checks on the array off IIRC and that >puzzels me. I guess, you are refering to ? Well, the catch here was, that a subtype declaration actually allows indexing an array with a "larger" type (like plain integer) than the actual constraints of the indices really are. If range checking is required or not then, simply depends on the type you use for indexing in a particular expression. Vinzent. --=20 Parents strongly cautioned -- this posting is intended for mature audiences over 18. It may contain some material that many parents would not find suitable for children and may include intense violence, sexual situations, coarse language and suggestive dialogue.