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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1fa85f3df5841ae1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada.Containers.Vectors - querying multiple elements Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> <0uYbe.542$BE3.229@newsread2.news.pas.earthlink.net> <1wjh6qsazg3rg$.lupowyuqu0tw$.dlg@40tude.net> Date: Sat, 30 Apr 2005 11:24:33 +0200 Message-ID: NNTP-Posting-Date: 30 Apr 2005 11:24:28 MEST NNTP-Posting-Host: e537932d.newsread4.arcor-online.net X-Trace: DXC=W7eK8UY1dQ1RTD7Kih:TB8:ejgIfPPld4jW\KbG]kaM8liQbn6H@_E9IaXZ3]`2nQ9[6LHn;2LCV>COgUkn_?_Y?WiRECcWkSV7 X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:10849 Date: 2005-04-30T11:24:28+02:00 List-Id: On Fri, 29 Apr 2005 15:26:31 -0500, Randy Brukardt wrote: > "Dmitry A. Kazakov" 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 := ; 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