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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-02 00:43:13 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!tar-atanamir.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada Date: Tue, 02 Dec 2003 09:47:03 +0100 Message-ID: References: <8urxb.19482$sb4.18182@newsread2.news.pas.earthlink.net> <1792884.HtYz4Yv8lY@linux1.krischik.com> NNTP-Posting-Host: tar-atanamir.cbb-automation.de (212.79.194.116) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1070354592 70091908 212.79.194.116 ([77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:3068 Date: 2003-12-02T09:47:03+01:00 List-Id: On Mon, 01 Dec 2003 16:57:37 +0100, Martin Krischik wrote: >Hyman Rosen wrote: > >> Jeffrey Carter wrote: >> > you cannot create a dangling reference with 'Access. >> >> How not? Just deallocate the object to which the pointer points. > >How will you do this without using some form of "Unchecked_"? Easily if the target is controlled. Consider this: with Ada.Finalization; package A is type Misty is new Ada.Finalization.Limited_Controlled with null record; procedure Finalize (X : in out Misty); end A; with Text_IO; use Text_IO; package body A is procedure Finalize (X : in out Misty) is begin Put_Line ("finalized!"); end Finalize; end A; with A; use A; with Text_IO; use Text_IO; procedure Test is begin Put_Line ("Begin of a scope"); declare type Pointer is access all Misty; X : Pointer; begin X := new Misty; -- This is not dangled! end; Put_Line ("End of the scope"); end Test; This program should print; Begin of a scope finalized! End of the scope All controlled objects allocated by the allocator new, being not explicity destroyed using Unchecked_Deallocation, will be destroyed upon finalization of the access type. -- Regards, Dmitry Kazakov http://www.dmitry-kazakov.de