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.118.21 with SMTP id z21mr9836626itb.18.1511562226947; Fri, 24 Nov 2017 14:23:46 -0800 (PST) X-Received: by 10.157.69.72 with SMTP id p8mr906944oti.4.1511562226872; Fri, 24 Nov 2017 14:23:46 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.stack.nl!goblin1!goblin2!goblin3!goblin.stu.neva.ru!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!d140no5644103itd.0!news-out.google.com!193ni1175iti.0!nntp.google.com!i6no5637014itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 24 Nov 2017 14:23:46 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.209.130.105; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 71.209.130.105 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: Fri, 24 Nov 2017 22:23:46 +0000 Content-Type: text/plain; charset="UTF-8" Xref: feeder.eternal-september.org comp.lang.ada:48184 Date: 2017-11-24T14:23:46-08:00 List-Id: On Friday, November 24, 2017 at 5:33:25 AM UTC-7, Jeffrey R. Carter wrote: > > I can't think of any situation when I'd need to access the same component of an > array using different indices, but I note that this compiles: > > procedure Renaming is > subtype T1 is String (1 .. 5); > subtype T2 is String (2 .. T1'Length + 1); > > S1 : T1 := "Hello"; > S2 : T2 renames S1; > begin -- Renaming > null; > end Renaming; This doesn't seem to solve the "duplicate indexing" need. I think my remark here restates AdaMagica's remark nearby. with Ada.Text_IO; use Ada.Text_IO; procedure Renaming is subtype T1 is String (1 .. 5); subtype T2 is String (2 .. T1'Length + 1); S1 : T1 := "Hello"; S2 : T2 renames S1; begin -- Renaming Put_Line("S1"); for i in S1'range loop Put(i'img & " "); Put(S1(i)); New_Line; end loop; New_Line; Put_Line("S2"); for i in S2'range loop Put(i'img & " "); Put(S2(i)); New_Line; end loop; New_Line; end Renaming; This outputs S1 1 H 2 e 3 l 4 l 5 o S2 1 H 2 e 3 l 4 l 5 o But a question: Is memory allocated for S2? Jerry