comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada.Containers.Vectors - querying multiple elements
Date: Sat, 30 Apr 2005 11:24:33 +0200
Date: 2005-04-30T11:24:28+02:00	[thread overview]
Message-ID: <txah28f4zlnp$.1pqea609lovyn.dlg@40tude.net> (raw)
In-Reply-To: G6idnbg9fbVACu_fRVn-1Q@megapath.net

On Fri, 29 Apr 2005 15:26:31 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:1wjh6qsazg3rg$.lupowyuqu0tw$.dlg@40tude.net...
> ...
>> I wonder if introducing ranges as a type class could mend this. Provided a
>> fictitious attribute Enum'Range (0) would return a null-length range, one
>> could then create empty arrays without referencing to any concrete index
>> bounds. But then Obj'First and Obj'Last could potentially raise
>> Constraint_Error, which might appear unpleasant but perfectly consistent.
>> Could there be a distributed overhead in the implementations of 'First and
>> 'Last then?
> 
> Yes, there would be a distributed overhead. For Janus/Ada (the only compiler
> for which I can speak definitively), in the general case array bounds are
> stored in a descriptor record, along with a dimension length and a pointer
> to the data. The dimension length is really redundant; I don't think most
> compilers store it separately. In order to be able to represent an array as
> you say, all compilers would have to store the dimension length and
> presumably a bit mask to specify which bounds are invalid and raise C_E if
> explicitly touched. And of course all references to 'First and 'Last would
> have to check the bit mask. Not too expensive, but certainly a significant
> change to compilers and some additional overhead.
>
> Array indexing in the general case subtracts 'First from the calculated
> value, so I don't think it would make sense to allow 'First to be an invalid
> value - at least not unless the length of the array was 0 (in which case it
> doesn't matter). But adding overhead to array indexing operations is not
> going to win anyone friends. :-) More seriously, I think it would be a
> non-starter.

I presume the compilers keep A'First and A'Last in T'Base, so all internal
index evaluations need not to check if 'First or 'Last is in T.

BTW, it seems that A'First is in T'Base anyway! I failed to find any clear
reference in ARM, but the following:

   X : String := "";
begin
   Ada.Text_IO.Put_Line (Integer'Image (X'First));

happily prints 0 with GNAT, no Constraint_Error!

As long as no empty enumeration *types* and no "mod 0" *types* allowed,
there is always a way to have A'First in T'Base (or better to say
"T'Implementation").

So the problem as I see it is with A'Last. Considering T is mod 1
implemented by some unsigned type, then A'First = 0, and 'Last is what? It
would be problematic to force all modular types to be internally
implemented as signed.

Yet one could have A'Last=T'Implementation'First and
A'First=T'Implementation'First+1 for empty arrays. Who cares?

Now consider the following test:

   type T is mod 1;
   type T_Array is array (T range <>);
   X : T_Array := <somehow-obtained-empty-array>;
begin
   for I in X'Range loop -- This is OK
      null;
   end loop;
   for I in X'First..X'Last loop -- This cannot be OK
      null;
   end loop;

Which is in a perfect contradiction with 3.6.2(7). It could probably be
mended too if we had universal index types. But this is yet another story.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-04-30  9:24 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-26 11:43 Ada.Containers.Vectors - querying multiple elements Duncan Sands
2005-04-26 14:12 ` Georg Bauhaus
2005-04-26 14:39   ` Duncan Sands
2005-04-26 15:44     ` Matthew Heaney
2005-04-26 16:05       ` Duncan Sands
     [not found]       ` <1114531544.32583.142.camel@localhost.localdomain>
     [not found]         ` <426E72C3.9070108@on2.com>
2005-04-26 16:59           ` Duncan Sands
     [not found]           ` <1114534751.32583.144.camel@localhost.localdomain>
     [not found]             ` <426E73DE.2070505@on2.com>
2005-04-26 17:08               ` Duncan Sands
2005-04-26 18:17                 ` Martin Dowie
2005-04-26 18:48                   ` Duncan Sands
2005-04-26 18:59           ` Duncan Sands
2005-04-26 19:05             ` Georg Bauhaus
2005-04-26 20:34               ` Duncan Sands
2005-04-26 21:47               ` Dr. Adrian Wrigley
2005-04-26 23:21                 ` Marius Amado Alves
     [not found]                 ` <9decddc0038674b3c85aeceefb4d3b83@netcabo.pt>
2005-04-27  8:15                   ` Duncan Sands
     [not found]                   ` <1114589729.10418.13.camel@localhost.localdomain>
2005-04-27 11:49                     ` Marius Amado Alves
2005-04-28  0:36                       ` Randy Brukardt
2005-04-28  7:09                         ` Duncan Sands
2005-04-27 11:10                 ` Georg Bauhaus
2005-04-27 11:57                   ` Duncan Sands
2005-04-28 14:17       ` Duncan Sands
2005-04-27  4:59   ` Jeffrey Carter
2005-04-27  7:21     ` Duncan Sands
2005-04-28  2:54       ` Jeffrey Carter
2005-04-28  7:15         ` Duncan Sands
2005-04-28 12:27           ` Matthew Heaney
2005-04-28 13:18           ` Matthew Heaney
2005-04-28 13:53             ` Duncan Sands
2005-04-29  2:46           ` Jeffrey Carter
2005-04-29 18:22             ` Robert A Duff
2005-04-28  7:18         ` Duncan Sands
2005-04-28  0:33     ` Randy Brukardt
2005-04-28  3:09       ` Jeffrey Carter
2005-04-28 20:55         ` Randy Brukardt
2005-04-29  2:54           ` Jeffrey Carter
2005-04-29 18:34             ` Robert A Duff
2005-04-29 20:18               ` Randy Brukardt
2005-04-29 20:00             ` Randy Brukardt
2005-04-30  4:06               ` Jeffrey Carter
2005-04-29  7:52           ` Dmitry A. Kazakov
2005-04-29 20:26             ` Randy Brukardt
2005-04-30  9:24               ` Dmitry A. Kazakov [this message]
2005-05-02  3:21                 ` Randy Brukardt
2005-05-02 17:04                   ` Dmitry A. Kazakov
2005-05-02 18:57                     ` Robert A Duff
2005-05-03  8:14                       ` Dmitry A. Kazakov
2005-05-03 23:30                         ` Robert A Duff
2005-05-05 10:51                           ` Dmitry A. Kazakov
2005-05-07  1:20                             ` Matthew Heaney
2005-05-07  7:17                               ` Dmitry A. Kazakov
     [not found] <1114515832.32583.41.camel@localhost.localdomain>
     [not found] ` <426E5A0B.3010109@on2.com>
2005-04-26 16:00   ` Duncan Sands
2005-04-28  0:54     ` Randy Brukardt
replies disabled

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