comp.lang.ada
 help / color / mirror / Atom feed
From: Vinzent Hoefler <ada.rocks@jlfencey.com>
Subject: Re: Optimizing Boundary Checks
Date: Fri, 13 Jun 2003 16:42:14 +0200
Date: 2003-06-13T16:42:14+02:00	[thread overview]
Message-ID: <bccnuv$i5af3$1@ID-175126.news.dfncis.de> (raw)
In-Reply-To: slrnbejlup.5eu.randhol+abuse@kiuk0152.chembio.ntnu.no

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 := 11;
>begin
>
>   Boxes (Index) := 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
<slrnbdpdan.87p.randhol+abuse@kiuk0152.chembio.ntnu.no>?

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.

-- 
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.



  reply	other threads:[~2003-06-13 14:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-13 11:49 Optimizing Boundary Checks Preben Randhol
2003-06-13 12:03 ` Erlo Haugen
2003-06-13 12:38   ` Vinzent Hoefler
2003-06-13 12:47     ` Preben Randhol
2003-06-13 13:28       ` Vinzent Hoefler
2003-06-13 12:42   ` Preben Randhol
2003-06-13 12:48     ` Preben Randhol
2003-06-13 13:28       ` Vinzent Hoefler
2003-06-13 13:56         ` Preben Randhol
2003-06-13 14:42           ` Vinzent Hoefler [this message]
2003-06-13 15:25             ` Preben Randhol
2003-06-13 15:34               ` Vinzent Hoefler
2003-06-14 10:45                 ` Preben Randhol
2003-06-14 14:59                   ` James Rogers
2003-06-13 13:33       ` Peter Amey
2003-06-13 13:34 ` Martin Dowie
2003-06-13 13:48   ` Vinzent Hoefler
2003-06-13 14:37     ` Martin Dowie
2003-06-13 15:12       ` Vinzent Hoefler
2003-06-14  2:01         ` Jeffrey Carter
2003-06-16 11:23           ` Vinzent Hoefler
2003-06-14  8:34         ` Dmitry A. Kazakov
2003-06-14 17:20         ` Robert I. Eachus
2003-06-16 11:23           ` Vinzent Hoefler
2003-06-18 20:58             ` Brian Gaffney
2003-06-13 13:45 ` Dale Stanbrough
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox