comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Will "renames" increase program size?
Date: Sat, 18 Jun 2011 12:05:54 +0200
Date: 2011-06-18T12:05:54+02:00	[thread overview]
Message-ID: <179qzjsdy73lo.a9h574vnyba4.dlg@40tude.net> (raw)
In-Reply-To: op.vw9kkbuvule2fv@douda-yannick

On Sat, 18 Jun 2011 10:58:49 +0200, Yannick Duch�ne (Hibou57) wrote:

> Le Sat, 18 Jun 2011 09:54:29 +0200, Dmitry A. Kazakov  
> <mailbox@dmitry-kazakov.de> a �crit:
>> Does this copy? It seems that according to you, you cannot tell without
>> looking into the body of Foo:
>>
>>    function Foo return T is -- This copies
>>       Result : T;
>>    begin
>>       return T;
>>    end Foo;
>>
>>    function Foo return T is -- This does not copy
>>    begin
>>       return Result : T;
>>    end Foo;
> 
> May be I did not really understood what you meant, but a simple test  
> program shows this makes no difference:

You have used integer, which is a scalar type. I am not a language layer,
though I guess that the compiler is required to copy in this case. But Adam
meant that for a controlled type it might be illegal to copy from the
return statement.

Here is a test:

with Ada.Finalization;
with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Copying is
   package P is
      type T is new Ada.Finalization.Controlled with record
         Name : Unbounded_String;
      end record;
      overriding procedure Adjust (X : in  out T);
      function Foo_1 (Name : String) return T;
      function Foo_2 (Name : String) return T;
   end P;
   package body P is
      procedure Adjust (X : in  out T) is
      begin
         Put_Line ("Adjust " & To_String (X.Name));
      end Adjust;
      function Foo_1 (Name : String) return T is
         Result : T;
      begin
         Append (Result.Name, Name);
         return Result;
      end Foo_1;
      function Foo_2 (Name : String) return T is
      begin
         return Result : T do
            Append (Result.Name, Name);
         end return;
      end Foo_2;
   end P;
   use P;
   X : T renames Foo_1 ("one way");
   Y : T renames Foo_2 ("another way");
begin
   null;
end Copying;

(My GNAT copies here as well.)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-06-18 10:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-15  2:10 Will "renames" increase program size? Adrian Hoe
2011-06-15  5:37 ` Randy Brukardt
2011-06-15  9:11   ` AdaMagica
2011-06-15 11:26     ` Yannick Duchêne (Hibou57)
2011-06-15 11:24   ` Yannick Duchêne (Hibou57)
2011-06-15 13:15     ` Dmitry A. Kazakov
2011-06-16  6:59       ` AdaMagica
2011-06-16  8:59         ` Dmitry A. Kazakov
2011-06-16 10:18           ` AdaMagica
2011-06-16 12:15             ` Dmitry A. Kazakov
2011-06-16 23:22             ` Randy Brukardt
2011-06-16 15:40           ` Adam Beneschan
2011-06-16 16:33             ` Dmitry A. Kazakov
2011-06-16 17:42               ` Adam Beneschan
2011-06-16 18:53                 ` Dmitry A. Kazakov
2011-06-16 23:39                   ` Randy Brukardt
2011-06-17  6:53                     ` Dmitry A. Kazakov
2011-06-18  0:02                       ` Randy Brukardt
2011-06-18  7:54                         ` Dmitry A. Kazakov
2011-06-18  8:58                           ` Yannick Duchêne (Hibou57)
2011-06-18 10:05                             ` Dmitry A. Kazakov [this message]
2011-06-18 12:49                               ` Yannick Duchêne (Hibou57)
2011-06-18 22:44                           ` Randy Brukardt
2011-06-22  0:56                             ` Shark8
2011-06-15 22:21 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox