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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5d3a1501d97dab65 X-Google-Attributes: gid103376,public From: "John G. Volan" Subject: Re: C to Ada : a piece of code Date: 1996/09/09 Message-ID: <3234D632.28EA@dayton.saic.com>#1/1 X-Deja-AN: 179615988 references: <3231732C.2781@virgoa4.in2p3.fr> <01bb9d61$537fe5e0$2b8371a5@dhoossr.iquest.com> <01bb9e40$d0312d80$348371a5@dhoossr.iquest.com> content-type: text/plain; charset=us-ascii organization: Science Applications International Corp. (SAIC) mime-version: 1.0 reply-to: John_Volan@dayton.saic.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0Gold (Macintosh; I; PPC) Date: 1996-09-09T00:00:00+00:00 List-Id: David C. Hoos, Sr. wrote: > > The trade off, (in those frequent cases where 0-based indexing is more > appropriate) is the one-time ugliness of the allocation, vs. the every time > ugliness of the references which need something like Vect'FIRST subtracted > during index computation. Not so fast, David! First of all, that's an under-the-hood implementation issue. Second of all, what you describe is only one possible implementation of array index computation, namely: item_address := first_item_address + (index - first_index) * item_size [where item_size = size of an item in storage units] But there is at least one other possible scheme (exploited by the GNAT compiler, I believe), which avoids that subtraction: item_address := zeroeth_item_address + index * item_size [where zeroeth_item_address = first_item_address - first_index * item_size] In other words, you pretend that the array extends beyond its lower end and hypothetically determine where the "zeroeth" item would be. You do this just once, and thereafter compute all your array offsets directly from your array indexes, without any subtraction, using this "zeroeth" address as the basis. As always, there's no risk of tromping on memory outside the array, because Ada's index constraints require index >= first_index. ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Home_Email => "John_Volan@syspac.com", Employer => "S.A.I.C.", Work_Email => "John_Volan@dayton.saic.com", Slogan => "Ada95: The World's *FIRST* International-Standard OOPL", Disclaimer => "My employer never defined these opinions, so using " & "them is totally erroneous...or is that a bounded error now? :-)"); ------------------------------------------------------------------------