comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Aliased
Date: Thu, 16 Jun 2005 19:35:31 -0700
Date: 2005-06-16T19:35:31-07:00	[thread overview]
Message-ID: <8t2dnaUiMJsyqy_fRVn-2w@comcast.com> (raw)
In-Reply-To: 1118930589.514028.150340@g47g2000cwa.googlegroups.com

<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???).

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) 





  parent reply	other threads:[~2005-06-17  2:35 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     ` Steve [this message]
2005-06-17  7:52       ` Aliased Dmitry A. Kazakov
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