comp.lang.ada
 help / color / mirror / Atom feed
From: leschkes@ferret.cig.mot.com (Scott Leschke)
Subject: Type conversion between access types (was: Free'ing extended types)
Date: 1996/05/20
Date: 1996-05-20T00:00:00+00:00	[thread overview]
Message-ID: <leschkes.832628057@ferret> (raw)
In-Reply-To: DqMH63.Jvw@world.std.com


On a related but different note, I was wondering about the effect of the
reserved word 'all' in the access type declarations below.  First I was
slightly surprised that the type conversions in the example code Bob Duff
posted were allowed since I know that independent access types (even those
specifying the same type) are viewed as denoting separate pools and as such
type conversions between them is not allowed.  This rule appears to go out
the window though if the 'all' modifier is used as in Bob's example.  To
paraphrase Jerry Seinfeld, "What's the deal with that?"

If you remove the 'all's from the declarations, the example ceases to
compile using GNAT 3.03 SunOS 4.1.3 giving the error message:

./pool_test.adb:19:14: invalid conversion, not compatible with type "BP"
defined at line X.

To sumarize:

 with Ada.Unchecked_Deallocation;

 procedure St is
    type a is tagged record X : Integer; end record;

    type ap is access a'class;

    procedure free is new Ada.unchecked_deallocation(A'class, ap);

    type b is new a with record
      Y : Integer; end record; -- a is extended

    type BP is access B'Class; -- ADDED THIS

    p : BP := new b; -- CHANGED THIS
    q: AP := AP(p); -- ADDED THIS

 begin
    free(Q); -- erroneous ?? -- CHANGED THIS
 end St;

gives:

./pool_test.adb:19:14: invalid conversion, not compatible with type "BP"
defined at line X.


BTW, If this is by some off chance highlights a bug in GNAT, please accept
my apologies up front for wasting bandwidth in this forum, but I don't
believe it is.



bobduff@world.std.com (Robert A Duff) writes:

>However, consider:

>with Ada.Unchecked_Deallocation;
>procedure St is
>   type a is tagged record X : Integer; end record;
>   type ap is access all a'class;
>   procedure free is new Ada.unchecked_deallocation(A'class, ap);
>   type b is new a with record
>     Y : Integer; end record; -- a is extended
>   type BP is access all B'Class; -- ADDED THIS

>   p : BP := new b; -- CHANGED THIS
>   q: AP := AP(p); -- ADDED THIS
>begin
>   free(Q); -- erroneous ?? -- CHANGED THIS
>end St;

[..] Other stuff omitted

>- Bob
-- 
Scott Leschke.........................email: leschkes@cig.mot.com
Motorola, Inc............................ph: 847-632-2786
1501 W Shure Drive......................fax: 847-632-3145
Arlington Heights, IL   60004......mailstop: 1301




  parent reply	other threads:[~1996-05-20  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-28  0:00 Free'ing extended types Jonas Nygren
1996-04-28  0:00 ` Robert Dewar
1996-04-29  0:00   ` Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00   ` Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00   ` Jonas Nygren
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00         ` Robert A Duff
1996-04-29  0:00       ` Jonas Nygren
1996-05-20  0:00       ` Scott Leschke [this message]
1996-05-21  0:00         ` Type conversion between access types (was: Free'ing extended types) Robert A Duff
1996-05-22  0:00           ` Scott Leschke
1996-05-23  0:00             ` Robert A Duff
1996-05-23  0:00               ` progers
1996-05-24  0:00               ` Scott Leschke
1996-05-24  0:00                 ` Robert A Duff
1996-05-21  0:00         ` Dale Stanbrough
1996-05-21  0:00           ` 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