comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <John_Volan@dayton.saic.com>
Subject: Re: C to Ada : a piece of code
Date: 1996/09/09
Date: 1996-09-09T00:00:00+00:00	[thread overview]
Message-ID: <3234D632.28EA@dayton.saic.com> (raw)
In-Reply-To: 01bb9e40$d0312d80$348371a5@dhoossr.iquest.com


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? :-)");
------------------------------------------------------------------------




  reply	other threads:[~1996-09-09  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-07  0:00 C to Ada : a piece of code Grave Xavier
1996-09-07  0:00 ` David C. Hoos, Sr.
1996-09-07  0:00 ` Robert A Duff
1996-09-08  0:00 ` Jon S Anthony
1996-09-08  0:00   ` David C. Hoos, Sr.
1996-09-09  0:00     ` nasser
1996-09-09  0:00   ` Jon S Anthony
1996-09-09  0:00     ` David C. Hoos, Sr.
1996-09-09  0:00       ` John G. Volan [this message]
1996-09-09  0:00       ` Robert Dewar
1996-09-10  0:00         ` Geert Bosch
1996-09-11  0:00           ` Robert Dewar
1996-09-13  0:00             ` Geert Bosch
1996-09-14  0:00               ` Robert Dewar
1996-09-11  0:00           ` Robert Dewar
1996-09-11  0:00             ` Jonas Nygren
1996-09-13  0:00             ` Geert Bosch
1996-09-14  0:00               ` Robert Dewar
1996-09-10  0:00 ` Jon S Anthony
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox