comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry <list_email@icloud.com>
Subject: Re: How to access an array using two different indexing schemes
Date: Fri, 24 Nov 2017 14:23:46 -0800 (PST)
Date: 2017-11-24T14:23:46-08:00	[thread overview]
Message-ID: <d67fd08c-ddd2-448c-b776-1bb3933949ce@googlegroups.com> (raw)
In-Reply-To: <ov93ij$njh$1@dont-email.me>

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


  parent reply	other threads:[~2017-11-24 22:23 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-24 11:42 How to access an array using two different indexing schemes Jerry
2017-11-24 12:33 ` Jeffrey R. Carter
2017-11-24 15:52   ` AdaMagica
2017-11-24 22:25     ` Jerry
2017-11-25 13:57       ` AdaMagica
2017-11-24 22:23   ` Jerry [this message]
2017-11-25 15:39   ` Robin
2017-11-25 20:58     ` Jerry
2017-11-26 10:22       ` Robin
2017-11-28 21:57       ` G. B.
2017-11-24 17:37 ` A. Cervetti
2017-11-24 21:48   ` Jerry
2017-11-24 22:15     ` Robert A Duff
2017-11-24 23:38       ` Jerry
2017-11-26  1:07         ` Jerry
2017-11-26  8:58           ` Dmitry A. Kazakov
2017-11-26 10:31             ` Jerry
2017-11-28  1:31             ` Randy Brukardt
2017-11-28  1:25   ` Randy Brukardt
2017-11-29  4:57     ` Jerry
2017-11-29 15:01       ` AdaMagica
2017-11-29 15:21         ` AdaMagica
2017-11-30  5:32           ` Jerry
2017-11-30  5:30         ` Jerry
2017-11-29 15:03       ` AdaMagica
2017-11-29 20:53         ` Randy Brukardt
2017-11-29 16:03       ` Shark8
2017-11-29 17:04         ` AdaMagica
2017-11-29 20:56           ` Randy Brukardt
2017-11-30  5:56             ` Jerry
2017-11-30 11:11               ` AdaMagica
2017-11-30 11:40                 ` AdaMagica
2017-11-30 14:47                   ` Niklas Holsti
2017-11-30 17:30                     ` AdaMagica
2017-11-30 19:31                       ` G. B.
2017-11-30 19:43                         ` Shark8
2017-11-30 22:10                           ` Randy Brukardt
2017-11-30 21:57                     ` Randy Brukardt
2017-11-30 22:49                 ` Jerry
2017-11-30 23:00                   ` Jerry
2017-11-30 21:50               ` Randy Brukardt
2017-11-30 23:13                 ` Jerry
2017-11-24 18:37 ` Per Sandberg
2017-11-24 21:28   ` Jerry
2017-11-24 21:40     ` Dmitry A. Kazakov
2017-11-28  1:33     ` Randy Brukardt
2017-11-24 22:12 ` Robert A Duff
2017-11-28  1:39   ` 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