From: "J-P. Rosen" <rosen@adalog.fr>
Subject: Re: Function definitions - with clarification
Date: Fri, 04 Jul 2014 08:45:23 +0200
Date: 2014-07-04T08:45:23+02:00 [thread overview]
Message-ID: <lp5ii4$4db$1@dont-email.me> (raw)
In-Reply-To: <53b2784d$0$6608$9b4e6d93@newsspool4.arcor-online.net>
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
next prev parent reply other threads:[~2014-07-04 6:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-22 11:34 Function definitions - with clarification montgrimpulo
2014-06-22 12:04 ` Simon Clubley
2014-06-22 14:25 ` montgrimpulo
2014-06-22 15:30 ` Georg Bauhaus
2014-06-22 17:29 ` montgrimpulo
2014-06-22 17:45 ` Shark8
2014-06-22 18:03 ` montgrimpulo
2014-06-22 18:45 ` Simon Clubley
2014-06-22 19:28 ` montgrimpulo
2014-06-22 21:04 ` Simon Wright
2014-06-22 21:17 ` Jeffrey Carter
2014-06-22 19:55 ` Shark8
2014-06-23 16:26 ` Adam Beneschan
2014-06-29 15:31 ` cotswold
2014-06-29 19:20 ` montgrimpulo
2014-06-30 9:29 ` G.B.
2014-06-30 17:55 ` Shark8
2014-07-01 8:58 ` Georg Bauhaus
2014-07-04 6:45 ` J-P. Rosen [this message]
2014-06-30 13:23 ` montgrimpulo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox