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: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.glorb.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Function definitions - with clarification Date: Fri, 04 Jul 2014 08:45:23 +0200 Organization: A noiseless patient Spider Message-ID: References: <53b12e15$0$6610$9b4e6d93@newsspool4.arcor-online.net> <53b2784d$0$6608$9b4e6d93@newsspool4.arcor-online.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 4 Jul 2014 06:45:25 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="d9450d091c91ffe3821246967870aca5"; logging-data="4523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rEA0QhW5fm4uEXfmDZOPv" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <53b2784d$0$6608$9b4e6d93@newsspool4.arcor-online.net> Cancel-Lock: sha1:Vj2WQbk70AYQY2pL7qt0pAvcGLQ= X-Enigmail-Version: 1.6 Xref: number.nntp.dca.giganews.com comp.lang.ada:187354 Date: 2014-07-04T08:45:23+02:00 List-Id: Le 01/07/2014 10:58, Georg Bauhaus a écrit : > On 30/06/14 19:55, Shark8 wrote: > 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.) > You can still free the locally allocated object, what you return is a copy of the T0 part of Result.all. Proof: try changing it to limited_control... -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr