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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bd1d347880390e54 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-15 18:43:20 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!npeer.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!82-43-33-75.cable.ubr01.croy.blueyonder.co.UK!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Type conversions on pool-specific access types Date: Thu, 16 Oct 2003 02:43:08 +0100 Message-ID: References: <7kukov45dif9p7u2ohu6ml29mu9cgu621o@4ax.com> Reply-To: "Nick Roberts" NNTP-Posting-Host: 82-43-33-75.cable.ubr01.croy.blueyonder.co.uk (82.43.33.75) X-Trace: news.uni-berlin.de 1066268587 24626705 82.43.33.75 (16 [25716]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Xref: archiver1.google.com comp.lang.ada:935 Date: 2003-10-16T02:43:08+01:00 List-Id: "Dmitry A. Kazakov" wrote in message news:7kukov45dif9p7u2ohu6ml29mu9cgu621o@4ax.com... > Who knows any reason why conversions between pool- > specific access types are not allowed, provided that > the storage pools are same? Isn't storage pool static- > ally known? > > It is a real pain to use Unchecked_Conversion ... I think it's also dangerous and unnecessary. > type Base is new Ada.Limited_Controlled with ..; > type Base_Ptr is access Base'Class; > for Base_Ptr'Storage_Pool use ...; > > procedure Foo (Object : Base_Ptr); > ... > type Derived is new Base with ..; > type Derived_Ptr is access Derived'Class; > for Derived_Ptr'Storage_Pool use Base_Ptr'Storage_Pool; > ... > declare > Ptr : Derived_Ptr := new Derived; > begin > Foo (Base_Ptr (Ptr)); -- ILLEGAL! > > I do not understand why. In this situation, I suggest that you do not need to declare Derived_Ptr, since Base_Ptr can -- and generally should -- be used to point to objects of type Derived (as well as Base). declare Ptr : Base_Ptr := new Derived; begin Foo(Ptr); > Another thing is initialization / finalization of controlled > objects allocated on some specific storage pool. It could > be a great problem if a pool-specific pointer is required ... The answer is "Don't do that!" Finalize should finalise whatever is inside the given Object, and not deal in any way with where (in which pool) the object resides. After the implementation has called Finalize for the object, it will then -- when appropriate -- call Deallocate for the object's pool, in order to deallocate the object's storage space from the pool. Do not mess with this mechanism. -- Nick Roberts