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!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.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: Thu, 30 Nov 2017 15:50:29 -0600 Organization: JSA Research & Innovation Message-ID: References: <0b6bd27e-e9ec-4854-bbb1-85e1d9ac92e1@googlegroups.com> <227d5a7f-6d5b-4b76-ac31-7d15bb6dc284@googlegroups.com> <16c980c2-1fa6-4084-97ea-b576c75b99c3@googlegroups.com> Injection-Date: Thu, 30 Nov 2017 21:50:29 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="9359"; 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; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:49281 Date: 2017-11-30T15:50:29-06:00 List-Id: "Jerry" wrote in message news:16c980c2-1fa6-4084-97ea-b576c75b99c3@googlegroups.com... > On Wednesday, November 29, 2017 at 1:56:59 PM UTC-7, Randy Brukardt wrote: >> "AdaMagica" wrote in message >> > Am Mittwoch, 29. November 2017 17:03:04 UTC+1 schrieb Shark8: >> > >> >> 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; >> > >> > No, that doesn't work! See previous posts. >> >> Should have showed what does work: >> >> Indexed : Indexing renames Indexing(Data); >> Offseted : Offset renames Offset(Data); >> >> The type conversions change the bounds as needed. Renames does not >> allocate >> new memory. >> >> Randy. > > Combining Shark8's plan with Randy's change and wrapping into a main > program like this: > > Procedure Shark8_And_Randy is > 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 Indexing(Data); > Offseted : Offset renames Offset(Data); > Begin > -- Stuffs! > null; > End Do_Stuffs; > Begin > null; > End Shark8_And_Randy; > > Results in GNAT complaining as such: > > shark8_and_randy.adb:9:37: renaming of conversion only allowed for tagged > types > shark8_and_randy.adb:10:35: renaming of conversion only allowed for tagged > types Sorry, my mistake. That probably will work in Ada 2020, but of course that's in the future. And even if it worked, the renames would be of a constant (as it would act like a renaming of a function call), which probably isn't what you had in mind. The only thing that does work is the type conversion in parameter passing (as I originally illustrated). So something like the following should work (should because I didn't try it): Procedure Randy_V2 is 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)); Procedure Really_Do_Stuff (Indexed : in out Indexing; Offseted : in out Offset) is Begin -- Stuff using Indexed and Offseted!! null; End Really_Do_Stuff; Begin Really_Do_Stuff (Indexing (Data), Offset(Data)); -- Parameter passing is the only way in Ada 83-2012 to get a view conversion -- of an untagged object. End Do_Stuffs; Begin null; End Randy_V2;