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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: How to access an array using two different indexing schemes Date: Mon, 27 Nov 2017 19:31:09 -0600 Organization: JSA Research & Innovation Message-ID: References: <0a928bc7-9681-4975-a130-55bf0f3264d0@googlegroups.com> <949666d5-1c4b-449d-a791-6a26f0b8e934@googlegroups.com> Injection-Date: Tue, 28 Nov 2017 01:31:09 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="14976"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:49207 Date: 2017-11-27T19:31:09-06:00 List-Id: "Dmitry A. Kazakov" wrote in message news:ovdvnm$3dt$1@gioia.aioe.org... > On 2017-11-26 02:07, Jerry wrote: >> On Friday, November 24, 2017 at 4:38:10 PM UTC-7, Jerry wrote: >>> I frequently allocate memory for arrays from the heap, as discussed >>> previously on this list, like this: >>> >>> with Ada.Numerics.Long_Real_Arrays; use Ada.Numerics.Long_Real_Arrays; >>> procedure Double_Array_2 is >>> type Real_Vector_Access is access Real_Vector; >>> x_Ptr : Real_Vector_Access := new Real_Vector(-4 .. 3); >>> x : Real_Vector renames x_Ptr.all; >>> y_Ptr : Real_Vector_Access := new Real_Vector(0 .. 7); >>> y : Real_Vector renames y_Ptr.all; >>> begin >>> null; >>> end Double_Array_2; >>> >>> How would I use the 'Address trick in this situation? Don't. Just type convert X as needed: with Ada.Numerics.Long_Real_Arrays; use Ada.Numerics.Long_Real_Arrays; procedure Double_Array_2 is type Real_Vector_Access is access Real_Vector; x_Ptr : Real_Vector_Access := new Real_Vector(-4 .. 3); x : Real_Vector renames x_Ptr.all; -- y_Ptr : Real_Vector_Access := new Real_Vector(0 .. 7); -->> This is allocating a new object for Real_Vector, which I don't think you want to do. subtype RV0_7 is Real_Vector(0..7); procedure Do_Y (Y : in out RV0_7) is begin -- Operations on Y. end Do_Y; begin Do_Y (RV0_7(X)); end Double_Array_2; If you used the Address clause hack here, you'd be subject to termination. GIGO. Randy.