comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Aliased
Date: Fri, 17 Jun 2005 09:52:46 +0200
Date: 2005-06-17T09:52:41+02:00	[thread overview]
Message-ID: <15o8r7mgwuzoq.19hxla355h14o$.dlg@40tude.net> (raw)
In-Reply-To: 8t2dnaUiMJsyqy_fRVn-2w@comcast.com

On Thu, 16 Jun 2005 19:35:31 -0700, Steve wrote:

> <nblanpain@hotmail.com> 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



  reply	other threads:[~2005-06-17  7:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 16:06 Aliased nblanpain
2005-06-15 16:35 ` Aliased Martin Dowie
2005-06-15 18:56 ` Aliased nblanpain
2005-06-15 21:47   ` Aliased Martin Dowie
2005-06-16  3:15 ` Aliased Steve
2005-06-16 14:03   ` Aliased nblanpain
2005-06-16 19:56     ` Aliased Simon Wright
2005-06-17  7:01       ` Aliased nblanpain
2005-06-17  9:38         ` Aliased Larry Kilgallen
2005-06-19 19:44           ` Aliased nblanpain
2005-06-19 20:33             ` Aliased Jeffrey Carter
2005-06-20  9:34               ` Aliased nblanpain
2005-06-20 16:41                 ` Aliased Jeffrey Carter
2005-06-17  2:15     ` Aliased Jeffrey Carter
2005-06-17  7:02       ` Aliased nblanpain
2005-06-17  2:35     ` Aliased Steve
2005-06-17  7:52       ` Dmitry A. Kazakov [this message]
2005-06-17  4:38     ` Aliased Christoph Grein
2005-06-29 21:10     ` Aliased Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox