Re: eliminating array bounds checking overhead

Ray Blaak <blaak@infomatch.com>
27 Apr 2000 10:46:00 -0400

          From comp.compilers

Related articles
eliminating array bounds checking overhead mayur_naik@my-deja.com (2000-04-26)
Re: eliminating array bounds checking overhead stephan@pcrm.win.tue.nl (2000-04-27)
Re: eliminating array bounds checking overhead vugluskr@unicorn.math.spbu.ru (2000-04-27)
Re: eliminating array bounds checking overhead jprice@scdt.intel.com (2000-04-27)
Re: eliminating array bounds checking overhead blaak@infomatch.com (Ray Blaak) (2000-04-27)
Re: eliminating array bounds checking overhead Sid-Ahmed-Ali.TOUATI@inria.fr (Sid Ahmed Ali TOUATI) (2000-04-27)
Re: eliminating array bounds checking overhead rhyde@shoe-size.com (Randall Hyde) (2000-04-27)
Re: eliminating array bounds checking overhead nr@labrador.eecs.harvard.edu (2000-04-27)
Re: eliminating array bounds checking overhead terryg@uswest.net (Terry Greyzck) (2000-04-27)
Re: eliminating array bounds checking overhead fjscipio@rochester.rr.com (Fred J. Scipione) (2000-04-27)
Re: eliminating array bounds checking overhead sandeep@ddi.com (Sandeep Dutta) (2000-04-29)
[12 later articles]
| List of all articles for this month |
From: Ray Blaak <blaak@infomatch.com>
Newsgroups: comp.compilers
Date: 27 Apr 2000 10:46:00 -0400
Organization: The Transcend
References: 00-04-194
Keywords: optimize, Ada

mayur_naik@my-deja.com writes:
> Does any language or any machine provide some mechanism to:
>
> 1. index an array without checking its bounds
> 2. throw an exception if the index was actually out of range
> 3. allow the programmer to catch and handle the exception rather than
> terminate the program


Well, Ada does. The strong typing gives information to the compiler for it to
deduce when range checking is not needed:


declare
    subtype Index is Integer range 1..10;
    type Arr is array (Index) of Integer;
    a : Arr;
    element : Integer;
    j : Index := 1;
    k : Integer := 11;
begin
    for i in a'Range loop
        element := a(i); -- no range checking needed, i is in range by definition
    end loop;
    a(j); -- range checking not needed, j is within Index by definition
    a(k); -- range checking needed due possibility of k being outside of Index
exception
    when Constraint_Error =>
          -- process the out-of-range error from a(k)
end;


--
Cheers, The Rhythm is around me,
                                                                                              The Rhythm has control.
Ray Blaak The Rhythm is inside me,
blaak@infomatch.com The Rhythm has my soul.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.