comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: How to access an array using two different indexing schemes
Date: Mon, 27 Nov 2017 19:25:25 -0600
Date: 2017-11-27T19:25:25-06:00	[thread overview]
Message-ID: <ovidu5$eip$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: e3a1f97e-7cbd-4327-aef6-c18ca9e74bc2@googlegroups.com

"A. Cervetti" <andrea.cervetti@gmail.com> wrote in message 
news:e3a1f97e-7cbd-4327-aef6-c18ca9e74bc2@googlegroups.com...
>use attribute 'Address:
>
>with Ada.Text_IO; use Ada.Text_IO;
>with Ada.Float_Text_IO; use Ada.Float_Text_IO;
>with Ada.Numerics.Generic_Real_Arrays;
>
>procedure Double_Array is
>   package Real_Array is new Ada.Numerics.Generic_Real_Arrays(Float);
>   use Real_Array;
>
>   x : Real_Vector(0 .. 4) := (1.0, 2.0, 3.0, 4.0, 5.0);
>   y : Real_Vector(1 .. 5);
>   for Y'Address use X'Address; -- <<<<<<<<<<<<<<<<<<<<

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.



begin
   X(0) := 20.0;
   Put(X(0), 0, 0, 0); New_Line;
   Put(Y(1), 0, 0, 0); New_Line;
end Double_Array;

A. 


  parent reply	other threads:[~2017-11-28  1:25 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
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 [this message]
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