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 06:29:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!feed.news.nacamar.de!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 15:28:06 +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 1055510975 18747682 213.200.246.247 (16 [175126]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:39107 Date: 2003-06-13T15:28:06+02:00 List-Id: Preben Randhol wrote: >Reason for asking is that I get: > >t.adb:10:11: warning: value not in range of subtype of = "Standard.integer" defined at line 6 >t.adb:10:11: warning: "constraint_error" will be raised at run time > >if I do: > > type Items is array (1 .. 10) of Natural; > Boxes : Items; > >begin > =20 > Boxes(11) :=3D 1; Well, yes. It can be determined at the time the code is compiled, because |1 < 11 or 11 > 10 simply results in True here, because everything is constant. Here the compiler even is allowed to not do anything at all with the array, instead it is enough to just generate the call to the exception handler. But if you'd like to try |i : Integer; | ... |i :=3D 11; |Boxes (i) :=3D 1; instead, then I guess, there will be no warning, because at the time the code is compiled, "i" will *not* be replaced by the constant 11 and the actual value of "i" is probably already out of scope for the compiler (highly depends on the implementation, I think). Although, any optimizing stage later probably still only generates a call to the exception handler if it is smart enough. If it is not, then there must be a range check here because |1 <=3D Integer'First or 10 >=3D Integer'Last results in False. Of course, my understanding of when a compiler generates a range check might be completely wrong, I am by no means a compiler writer. :) 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.