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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,a41c4a2c795dbe34 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!138.195.8.3.MISMATCH!news.ecp.fr!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Will "renames" increase program size? Date: Sat, 18 Jun 2011 12:05:54 +0200 Organization: cbb software GmbH Message-ID: <179qzjsdy73lo.a9h574vnyba4.dlg@40tude.net> References: <46294109-f07d-49c0-8e81-65a369a05ced@z15g2000prn.googlegroups.com> <1ayjsy885qg2b$.13bmeo97hbau1$.dlg@40tude.net> <316ac8ed-1ded-43d0-98d1-36bb2c0221ad@f2g2000yqh.googlegroups.com> <2e8222df-9b82-497f-9dc4-5cb0d5653550@f31g2000pri.googlegroups.com> <1t5j5p8gurul3$.k4cq2qnsbbjb.dlg@40tude.net> <12lr1j2mmzidu.18gjo4p3e73kk$.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: oh+M5iQyFLSJIOzWXBo0Zw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news1.google.com comp.lang.ada:19952 Date: 2011-06-18T12:05:54+02:00 List-Id: 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 > 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