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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 01 Jul 2014 10:58:52 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Function definitions - with clarification References: <53b12e15$0$6610$9b4e6d93@newsspool4.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <53b2784d$0$6608$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 01 Jul 2014 10:58:54 CEST NNTP-Posting-Host: 34427c17.newsspool4.arcor-online.net X-Trace: DXC=RN=j>e:GXJSAX0F2i>ejVX]3dW3ZJlZ4ZkoSA1ifOBPP X-Complaints-To: usenet-abuse@arcor.de Xref: news.eternal-september.org comp.lang.ada:20656 Date: 2014-07-01T10:58:54+02:00 List-Id: On 30/06/14 19:55, Shark8 wrote: > Given that the access-type is local to the function, when the function goes out of scope [due returning] the access-type itself should as well, taking all the allocated values with it, right? The parts local to the function just become inaccessible, but they exist, and they need to exist after return. Consider, for example, type T0 is new Ada.Finalization.Controlled with record A: Character := '#'; end record; function F return T0'Class is type T1 is new T0 with record N : Natural; end record; begin declare type Heap_Thing is access T1; Result : Heap_Thing; begin Result := new T1'(Controlled with A => '*', N => 42); return T0 (Result.all); end; end F; If T0 has a component A : Character as indicated above, then the following statement should print '*': Put (F.A); Things will be more interesting in case F returns an anonymous access T0'Class. (Seems a mine field, then, at least if T0 is derived from Finalization.Controlled.)