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.36.19.193 with SMTP id 184mr4206474itz.48.1511971382683; Wed, 29 Nov 2017 08:03:02 -0800 (PST) X-Received: by 10.157.42.99 with SMTP id t90mr73809ota.5.1511971382574; Wed, 29 Nov 2017 08:03:02 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!i6no778317itb.0!news-out.google.com!x87ni955ita.0!nntp.google.com!i6no778316itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 29 Nov 2017 08:03:02 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.148.6.150; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 155.148.6.150 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0b6bd27e-e9ec-4854-bbb1-85e1d9ac92e1@googlegroups.com> Subject: Re: How to access an array using two different indexing schemes From: Shark8 Injection-Date: Wed, 29 Nov 2017 16:03:02 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:49249 Date: 2017-11-29T08:03:02-08:00 List-Id: On Tuesday, November 28, 2017 at 9:57:48 PM UTC-7, Jerry wrote: > > 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; Subtype Real is Float range Float'Range; -- Get rid of non-numeric. Type General_Real_Array is Array(Integer range <>) of Real; Procedure Do_Stuffs( Data : in out General_Real_Array ) is Subtype Indexing is General_Real_Array(1..Data'Length); Subtype Offset is General_Real_Array(0..Integer'Pred(Data'Length)); Indexed : Indexing renames Data; Offseted : Offset renames Data; Begin -- Stuffs! null; End Do_Stuffs;