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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,af3dada69080e420 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-23 01:09:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!dialin-145-254-039-164.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Interesting effects in array renaming Date: Mon, 23 Jun 2003 10:12:30 +0200 Organization: At home Message-ID: References: <3EF5E6B8.3030203@spam.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-039-164.arcor-ip.net (145.254.39.164) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1056355788 26498017 145.254.39.164 (16 [77047]) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:39584 Date: 2003-06-23T10:12:30+02:00 List-Id: Jeffrey Carter wrote: > Dmitry A. Kazakov wrote: >> ---------- test.adb >> with Ada.Text_IO; use Ada.Text_IO; >> >> procedure Test is >> type Some_Array is array (Integer range <>) of Integer; >> >> procedure Foo (X : Some_Array) is >> subtype Constrained is Some_Array (1..X'Length); >> XX : Constrained renames X; >> begin >> Put_Line >> ( "XX'Range:" >> & Integer'Image (XX'First) >> & ".." >> & Integer'Image (XX'Last) >> & ", Constrained'Range:" >> & Integer'Image (Constrained'First) >> & ".." >> & Integer'Image (Constrained'Last) >> ); >> end Foo; >> >> Object : Some_Array (-3..2) := (-3, -2, -1, 0, 1, 2); >> begin >> Foo (Object); >> end Test; >> ---------- test.adb >> >> Surprisingly the above produces different ranges for XX and its declared >> subtype. Isn't something wrong here? > > Note that you can also do > > subtype Constrained is Some_Array (1..X'Length-1); > > or > > subtype Constrained is Some_Array (1..3); > > with similar results. You can also do > > XX : Some_Array renames X; > > which perhaps demonstrates more clearly where the object's subtype comes > from. I see no link with subtypes. ARM clearly states: 8.5.1(6) "... any constraint implied by the subtype_mark of the object_renaming_declaration is ingored)." I.e. whatever subtype you, a programmer, might specify I, the compiler, will shamelessly ignore it! How safe! Do you really think it is OK? Consider this: X1 : Constrained := Constrained (X); X2 : Constrained renames X; What is OK here, that X1 and X2 have different constraints or that X2 is potentially invalid? I see only two alternatives: Either to add a dynamic semantics ensuring that the result of renaming is a valid object of the declared subtype. [X2 raises Constraint_Error if Constrained'Range /= X'Range] Or [painful] to require X1 and X2 be same in all cases, and thus: XX : Some_Array renames X (X'First + 1 .. X'Last); would have length different from X, so a new array dope has to be generated etc. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de