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-Thread: 103376,98e3ee7e73b9dd89 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!news-FFM2.ecrc.net!noris.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Aliased Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1118851601.345326.86640@g49g2000cwa.googlegroups.com> <1118930589.514028.150340@g47g2000cwa.googlegroups.com> <8t2dnaUiMJsyqy_fRVn-2w@comcast.com> Date: Fri, 17 Jun 2005 09:52:46 +0200 Message-ID: <15o8r7mgwuzoq.19hxla355h14o$.dlg@40tude.net> NNTP-Posting-Date: 17 Jun 2005 09:52:41 MEST NNTP-Posting-Host: 2855f4d0.newsread2.arcor-online.net X-Trace: DXC=n99UjjCOoRBUhhl_USDNiOQ5U85hF6f;DjW\KbG]kaMHFYk:AnJB[CMbTfcCacN4dB[6LHn;2LCVN7enW;^6ZC`D<=9bOTW=MNN X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:11445 Date: 2005-06-17T09:52:41+02:00 List-Id: On Thu, 16 Jun 2005 19:35:31 -0700, Steve wrote: > wrote in message > news:1118930589.514028.150340@g47g2000cwa.googlegroups.com... >> So this is my sources and the compilation error : >> >> ------ Container.ads > [snip] >> >> ------ Container.adb > [snip] >> >> -- Compilation Error : Object subtype must statically match designated >> subtype. No local pointer cannot point to local object. >> >> I have tried to solve this problem using Unchecked_Access or To_Pointer >> of System. I have found no solution. >> Have you a solution to my problem? >> >> Thanks, >> > > Ahh... now I recognize the problem. Here is (what I think is) a simpler > example to illustrate: > > procedure Simple_Case is > > type String_Acc is access all String; > > instance_1 : aliased String := "Hello"; > instance_2 : aliased String( 1..5 ); > accessor : String_Acc; > > begin > instance_2 := "Hello"; > accessor := instance_1'Unchecked_Access; > accessor := instance_2'Unchecked_Access; > end Simple_Case; > > The error reads: > simple_case.adb:12:17 object subtype must statically match designated > subtype > > Generally speaking I really like Ada, but this is an example of one of the > quirks that I think needs fixing (maybe it will be fixed in Ada 200x???). I think it is reasonable. A fix should be rather introducing 'Class for all types. Then one could: type String_Acc is access all String'Class; -- Fat pointer containing the bounds, can point to string slices! instance_1 : aliased String := "Hello"; instance_2 : aliased String( 1..5 ); accessor : String_Acc; begin instance_2 := "Hello"; accessor := instance_1'Unchecked_Access; accessor := instance_2'Unchecked_Access; > In my example the type String_Acc is defined to access subtypes of String > that are not bounded. > "instance_1" is defined a subtype of string that is not bounded, but with an > initializer, so it is ok to assign an access to instance_1 to "accessor". > "instance_2" is defined as a fixed length subtype of string, which is > bounded, so it is not ok to assign an access to instance_2 to accessor. > > The Folks at AdaCore recognized that this was a silly requirement and > created a special pragma that is more flexible for this case. I don't know GNAT implementation details, but if there were no difference between pointers to bounded and unbounded objects, then either every pointer should contain the bounds or every object should. Either choice has disadvantages of its own. Ada's idea to separate these cases looks to me perfectly good. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de