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,FREEMAIL_FROM autolearn=ham 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!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 16 Jun 2005 21:34:23 -0500 From: "Steve" Newsgroups: comp.lang.ada References: <1118851601.345326.86640@g49g2000cwa.googlegroups.com> <1118930589.514028.150340@g47g2000cwa.googlegroups.com> Subject: Re: Aliased Date: Thu, 16 Jun 2005 19:35:31 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <8t2dnaUiMJsyqy_fRVn-2w@comcast.com> NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-zQaYotcKrrte0pZsOlwqdRFUwQwsHba6SnExaLbZtix53GKoOf4eZQOdY08fvAplhYo0ovL2XQfMGDA!SfcmGaCps+5/vZHXX87cXOaZOd2/slPY8JseyCagEJJTy3Et6dPjW0wEn1kC X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:11439 Date: 2005-06-16T19:35:31-07:00 List-Id: 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???). 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. If you change the above code to read: accessor := instance_2'Unrestricted_Access; GNAT is happy. Unforutnately this is compiler specific. In case my above example wasn't clear, the following code makes the compiler happy: procedure Simple_Case is subtype String_5 is String( 1.. 5 ); type String_Acc is access all String; type String_5_Acc is access all String_5; instance_1 : aliased String := "Hello"; instance_2 : aliased String( 1..5 ); accessor_1 : String_Acc; accessor_2 : String_5_Acc; begin instance_2 := "Hello"; accessor_1 := instance_1'Unchecked_Access; accessor_2 := instance_2'Unchecked_Access; end Simple_Case; Unfortunately it doesn't solve your problem. Steve (The Duck)