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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,9adfbb907494972e X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,9adfbb907494972e X-Google-Attributes: gid103376,public From: "Tim Behrendsen" Subject: Re: Ada to C/C++ translator needed Date: 1996/09/30 Message-ID: <01bbaef3$73605680$87ee6fce@timpent.a-sis.com>#1/1 X-Deja-AN: 186271649 references: <32499FA0.4B5E@magic.fr> <52e5t5$m28@btmpjg.god.bel.alcatel.be> <52feul$os2@goanna.cs.rmit.edu.au> <01bbad6e$67743f20$32ee6fcf@timhome2> <52ltk5$qlf@news1.halcyon.com> <01bbae25$67c669a0$32ee6fcf@timhome2> <01bbae8f$dffbd440$32ee6fcf@timhome2> content-type: text/plain; charset=ISO-8859-1 organization: A-SIS mime-version: 1.0 newsgroups: comp.lang.c,comp.lang.ada Date: 1996-09-30T00:00:00+00:00 List-Id: Matthew Heaney wrote in article ... > In article <01bbae8f$dffbd440$32ee6fcf@timhome2>, "Tim Behrendsen" > 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)