From: reinert <reinkor@gmail.com>
Subject: Question on in/out parameters
Date: Sat, 30 Apr 2022 01:57:37 -0700 (PDT) [thread overview]
Message-ID: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com> (raw)
Hello,
I expected an "out" parameter in a procedure to be like declaring the parameter "from scratch" (with actual initial default value). For my compiler (GNAT Community Edition, May 2021) it seems like the out parameters brings in content from the calling procedure. Should it be like this?
Below is a test program to illustrate.
reinert
with Ada.Containers; use Ada.Containers;
with Ada.Containers.Vectors;
with Ada.Text_IO; use Ada.Text_IO;
procedure test2 is
package Integer_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural, Element_Type => Integer);
use Integer_Vectors;
V : Vector := 10 & 20;
procedure rk_in_out(W : in out Vector) is
begin
W.Append(30); W.Append(40);
end rk_in_out;
procedure rk_out(W : out Vector) is
begin
W.Clear; -- I expected this statement to be redundant since W is "out parameter" (try to remove it and see if results remain the same.)?
W.Append(30); W.Append(40);
end rk_out;
begin
New_Line;
Put ("First V : ");
for e of V loop
Put(e'Image & " ");
end loop;
rk_in_out(W => V);
New_Line;
Put ("Second V : ");
for e of V loop
Put(e'Image & " ");
end loop;
rk_out(W => V);
New_Line;
Put ("Third V : ");
for e of V loop
Put(e'Image & " ");
end loop;
end test2;
next reply other threads:[~2022-04-30 8:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-30 8:57 reinert [this message]
2022-04-30 9:38 ` Question on in/out parameters Jeffrey R.Carter
2022-04-30 11:30 ` reinert
2022-05-01 7:50 ` J-P. Rosen
2022-05-02 21:35 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox