From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Ada to C/C++ translator needed
Date: 1996/09/30
Date: 1996-09-30T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023180003009960805430001@news.ni.net> (raw)
In-Reply-To: 01bbae8f$dffbd440$32ee6fcf@timhome2
In article <01bbae8f$dffbd440$32ee6fcf@timhome2>, "Tim Behrendsen"
<tim@airshields.com> wrote:
>I know that Ada does run-time checks of array bounds that C
>doesn't do; that could be one source of loss of performance.
>Does Ada do any other run-time checks that C doesn't do?
Not necessarily. Using a subtype actually *turns off* type checking during
iteration through an array.
If I did this
type AT is array (Positive range <>) of T;
O : AT (1 .. 10);
begin
for I in 1 .. 10 loop
O (I) :- ...
Then I might very well incur a check. But by asserting a more specific
type for the loop index, no checks will be made inside the loop:
for I in O'Range loop
O (I) -- no check, since I is guaranteed to to be in the range of O
Or
subtype Index is Positive range 1 .. 10;
O : AT (Index);
begin
for I in Index loop
O (I) -- no check required inside the loop
If I didn't want to iterate through all the items in O, then I (the human)
would still include a subtype for I (the index):
O : AT (Index);
begin
for I in Index range 2 .. 8 loop
O (I)...
Here you are asserting that I lies in the index subtype of O. The checking
of that assertion need only take place once, on entry to the loop.
It's a common misunderstanding that a subtype puts checks in, but very
often just the opposite is true. The idea is the give the compiler as much
information as you can when declaring the index that dereferences an array
object. For example:
O : AT (1 .. 10);
I : Positive range O'Range;
begin
...
O (I) ... -- no check required
or
subtype Index is Positive range 1 .. 10;
O : AT (Index);
I : Index;
begin
...
O (I) ...
>-- Tim Behrendsen (tim@a-sis.com)
Matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271
next prev parent reply other threads:[~1996-09-30 0:00 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-09-25 0:00 Ada to C/C++ translator needed Emmanuel Champommier
1996-09-25 0:00 ` David Weller
1996-10-02 0:00 ` B|rje Norden
1996-10-04 0:00 ` David Weller
1996-10-05 0:00 ` Robert Dewar
1996-10-05 0:00 ` Frank Manning
1996-10-06 0:00 ` Samuel Tardieu
1996-10-07 0:00 ` Richard Kenner
1996-10-07 0:00 ` Robert Dewar
1996-10-08 0:00 ` Stephen Leake
1996-10-07 0:00 ` Robert Dewar
1996-10-08 0:00 ` Frank Manning
1996-10-07 0:00 ` Erik Magnuson
1996-09-26 0:00 ` Ian Ward
1996-10-02 0:00 ` Jon S Anthony
1996-10-02 0:00 ` Jon S Anthony
[not found] ` <52feul$os2@goanna.cs.rmit.edu.au>
1996-09-28 0:00 ` Tim Behrendsen
1996-09-29 0:00 ` Ken Pizzini
1996-09-29 0:00 ` Tim Behrendsen
1996-09-29 0:00 ` Robert Dewar
1996-09-30 0:00 ` Tim Behrendsen
1996-09-30 0:00 ` William Clodius
1996-09-30 0:00 ` Matthew Heaney [this message]
1996-09-30 0:00 ` Tim Behrendsen
1996-10-01 0:00 ` Richard A. O'Keefe
1996-09-30 0:00 ` Richard A. O'Keefe
1996-09-30 0:00 ` Tim Behrendsen
1996-09-30 0:00 ` Richard A. O'Keefe
1996-09-30 0:00 ` Peter Seebach
1996-10-02 0:00 ` Richard A. O'Keefe
1996-10-05 0:00 ` Lawrence Kirby
1996-09-30 0:00 ` Tim Behrendsen
1996-09-30 0:00 ` Peter Seebach
1996-09-30 0:00 ` Tim Behrendsen
1996-10-01 0:00 ` Richard A. O'Keefe
1996-10-01 0:00 ` Tim Behrendsen
1996-10-02 0:00 ` Ian Ward
1996-10-02 0:00 ` Tim Behrendsen
1996-10-06 0:00 ` Tanmoy Bhattacharya
1996-10-06 0:00 ` Lawrence Kirby
1996-10-08 0:00 ` Peter Seebach
1996-10-07 0:00 ` Tanmoy Bhattacharya
-- strict thread matches above, loose matches on Subject: below --
1996-10-02 0:00 Simon Johnston
1996-10-07 0:00 ` Richard Riehle
1996-10-09 0:00 ` Richard A. O'Keefe
1996-10-15 0:00 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox