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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2866100c9a2b8ce7 X-Google-Attributes: gid103376,public From: leschkes@ferret.cig.mot.com (Scott Leschke) Subject: Type conversion between access types (was: Free'ing extended types) Date: 1996/05/20 Message-ID: #1/1 X-Deja-AN: 155817417 references: <3183AC75.335C@ehs.ericsson.se> <3184803D.1208@ehs.ericsson.se> organization: Motorola Cellular Infrastructure Group newsgroups: comp.lang.ada Date: 1996-05-20T00:00:00+00:00 List-Id: 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