comp.lang.ada
 help / color / mirror / Atom feed
* Question on in/out parameters
@ 2022-04-30  8:57 reinert
  2022-04-30  9:38 ` Jeffrey R.Carter
  2022-05-02 21:35 ` Randy Brukardt
  0 siblings, 2 replies; 5+ messages in thread
From: reinert @ 2022-04-30  8:57 UTC (permalink / 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;


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-02 21:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-30  8:57 Question on in/out parameters reinert
2022-04-30  9:38 ` Jeffrey R.Carter
2022-04-30 11:30   ` reinert
2022-05-01  7:50     ` J-P. Rosen
2022-05-02 21:35 ` Randy Brukardt

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