comp.lang.ada
 help / color / mirror / Atom feed
From: "Tim Behrendsen" <tim@a-sis.com>
Subject: Re: Ada to C/C++ translator needed
Date: 1996/09/30
Date: 1996-09-30T00:00:00+00:00	[thread overview]
Message-ID: <01bbaef3$73605680$87ee6fce@timpent.a-sis.com> (raw)
In-Reply-To: mheaney-ya023180003009960805430001@news.ni.net


Matthew Heaney <mheaney@ni.net> wrote in article
<mheaney-ya023180003009960805430001@news.ni.net>...
> 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.  
> [snip example]

> 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:
>[snip example]

So it is possible to give the compiler enough hints to eliminate
the check in looping cases.  In fact, I would expect the compiler
could be smart enough to detect (excuse C syntax)

for (i = 0; i < n; ++i) {
    if (A[i] > j)
        ...
}

It knows the working range of i is 0..n, so it could do the
bounds check once (A[n]) at the beginning of the loop.

All that having been said, I wonder how much bounds checking
is actually kept in a real good-sized project where you are
passing general values into subroutines that get used as
array indexes (where the compiler couldn't necessarily validate
at compile time)?

To tell you the truth, I doubt it's a big deal, unless the
latter subroutine call is being used in a hard loop, and you're
doing character-by-character processing or something. Then the
bounding checks could start adding up.

-- Tim Behrendsen (tim@a-sis.com)




  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
1996-09-30  0:00                 ` Tim Behrendsen [this message]
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         ` 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-09-30  0:00         ` Peter Seebach
1996-10-02  0:00           ` Richard A. O'Keefe
1996-10-05  0:00             ` Lawrence Kirby
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