From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Will "renames" increase program size?
Date: Sat, 18 Jun 2011 10:58:49 +0200
Date: 2011-06-18T10:58:49+02:00 [thread overview]
Message-ID: <op.vw9kkbuvule2fv@douda-yannick> (raw)
In-Reply-To: c8ynrt1qxx83.1vaqckntoa8r5$.dlg@40tude.net
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:
-- Begin Test.adb
------------------------------------------------------------
with Ada.Text_IO;
procedure Test is
Foo_1_Seed : Integer := 0;
function Foo_1 return Integer
is
Result : constant Integer := Foo_1_Seed;
begin
Foo_1_Seed := Foo_1_Seed + 1;
return Result;
end;
Foo_2_Seed : Integer := 0;
function Foo_2 return Integer is
begin
return Result : constant Integer := Foo_2_Seed do
Foo_2_Seed := Foo_2_Seed + 1;
end return;
end;
Foo_1_1 : Integer renames Foo_1;
Foo_1_2 : Integer renames Foo_1;
Foo_1_3 : Integer renames Foo_1;
Foo_2_1 : Integer renames Foo_2;
Foo_2_2 : Integer renames Foo_2;
Foo_2_3 : Integer renames Foo_2;
procedure Put (Label : in String; Value : in Integer) is
package Text_IO renames Ada.Text_IO;
package Integer_IO is new Ada.Text_IO.Integer_IO (Integer);
begin
Text_IO.Put (Label);
Text_IO.Put (" is ");
Integer_IO.Put (Value);
Text_IO.New_Line;
end;
begin
Put (Label => "Foo_1_1", Value => Foo_1_1);
Put (Label => "Foo_1_2", Value => Foo_1_2);
Put (Label => "Foo_1_3", Value => Foo_1_3);
Put (Label => "Foo_2_1", Value => Foo_2_1);
Put (Label => "Foo_2_2", Value => Foo_2_2);
Put (Label => "Foo_2_3", Value => Foo_2_3);
end Test;
-- End of Test.adb
-----------------------------------------------------------
And the output:
-- Begin Output ------
Foo_1_1 is 0
Foo_1_2 is 1
Foo_1_3 is 2
Foo_2_1 is 0
Foo_2_2 is 1
Foo_2_3 is 2
-- End of Output -----
--
“Syntactic sugar causes cancer of the semi-colons.” [Epigrams on
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
Java: Write once, Never revisit
next prev parent reply other threads:[~2011-06-18 8:58 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) [this message]
2011-06-18 10:05 ` Dmitry A. Kazakov
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