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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.191.7 with SMTP id p7mr1091001iof.130.1511931466875; Tue, 28 Nov 2017 20:57:46 -0800 (PST) X-Received: by 10.157.1.175 with SMTP id e44mr33485ote.1.1511931466803; Tue, 28 Nov 2017 20:57:46 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!193no388930itr.0!news-out.google.com!x87ni451ita.0!nntp.google.com!i6no392138itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 28 Nov 2017 20:57:46 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=97.117.255.82; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 97.117.255.82 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to access an array using two different indexing schemes From: Jerry Injection-Date: Wed, 29 Nov 2017 04:57:46 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:49235 Date: 2017-11-28T20:57:46-08:00 List-Id: On Monday, November 27, 2017 at 6:25:26 PM UTC-7, Randy Brukardt wrote: > > An evil and not guaranteed to work on all implementation technique. > > The OP just needs to use an appropriate type conversion to change the bounds > of their array (odd no one has mentioned that): > > If one has: > > subtype RV1_5 is Real_Vector(1..5); > > Then the type conversion: > RV1_5(X) has the new bounds, and (by itself) doesn't copy any memory. > > Thus, using a subprogram to temporarily bind the object shouldn't result in > any copying of the data (no guarantees, of course, but it will always work - > rememberm avoid premature optimization!): > > procedure Do_Y (Y : RV1_5) is > begin > -- Operations on Y. > end Do_Y; > > ... > Do_Y (RV1_5(X)); > > This is the best way to change the bounds of an array (or part of an array) > in Ada. > > Randy. Your method shows how to pass the re-dimensioned array to a subprogram for processing with a typecast. But I also need to process the array in the same program that the subtype is declared. How would I do the typecast without allocating more memory? Something like this: procedure Doubly_Indexed_Array is declare x with dimensions (0 .. 4) declare y with dimensions (1 .. 5) using the same memory as x but accessed with different indices begin x(0) := 10.0; y(3) := 20.0; print x(0) resulting in 10.0 print y(1) resulting in 10.0 print x(2) resulting in 20.0 print y(3) resulting in 20.0 end Doubly_Indexed_Array; Jerry