comp.lang.ada
 help / color / mirror / Atom feed
From: stuartw@tove.cs.umd.edu (Stuart M. Weinstein)
Subject: Updating IN OUT's after exceptions
Date: 30 Apr 91 09:18:41 GMT	[thread overview]
Message-ID: <33747@mimsy.umd.edu> (raw)

In the enclosed program, I raise an exception inside a subroutine after
making an assignment to an IN OUT parameter.  In the first case, the
parameter is a scalar, in the second it is not.  Everything else is the
same, except the resulting behavior.  Is this permitted by the LRM?
I know that compilers can pass non-scalar parameters by copy-in/copy-out
or reference, but should that effect exception handling?  Is Ada/9x
addressing this?

Thanks.

Stuart.  (weinstei@kong.gsfc.nasa.gov)

\f
with text_io;
procedure t1 is

  type intarr is array(1..50) of integer;
  zero : integer;
  a    : integer;
  arr  : intarr;

  procedure sub1(x : in out integer) is
    y : integer := 1;
  begin
    x := x + 10;
    y := y / zero; -- raise exception
  end sub1;

  procedure sub2(x : in out intarr; i : in integer) is
    y : integer := 1;
  begin
    x(i) := x(i) + 10;
    y    := y / zero; -- raise exception
  end sub2;

begin

  zero := 0;
  a := 5;
  text_io.put_line("Before sub1: A = " & integer'image(a));
  begin sub1(a); exception when others => null; end;
  text_io.put_line("After  sub1: A = " & integer'image(a));

  arr(12) := 5;
  text_io.put_line("Before sub1: ARR(12) = " & integer'image(arr(12)));
  begin sub2(arr,12); exception when others => null; end;
  text_io.put_line("After  sub1: ARR(12) = " & integer'image(arr(12)));

end;

Output from DEC Ada 2.2:

Before sub1: A =  5
After  sub1: A =  5
Before sub1: ARR(12) =  5
After  sub1: ARR(12) =  15

             reply	other threads:[~1991-04-30  9:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-04-30  9:18 Stuart M. Weinstein [this message]
1991-05-01 22:56 ` Updating IN OUT's after exceptions stt
1991-05-02 17:10   ` Doug Smith
1991-05-03 12:51   ` Bill Lee
replies disabled

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