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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: mheaney@ni.net (Matthew Heaney) Subject: Re: Ada to C/C++ translator needed Date: 1996/09/30 Message-ID: #1/1 X-Deja-AN: 186247317 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: Estormza Software mime-version: 1.0 newsgroups: comp.lang.c,comp.lang.ada Date: 1996-09-30T00:00:00+00:00 List-Id: 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. 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