comp.lang.ada
 help / color / mirror / Atom feed
* Extended return question
@ 2008-07-10  2:11 Dale Stanbrough
  2008-07-10  7:18 ` Georg Bauhaus
  2008-07-10 14:37 ` Robert A Duff
  0 siblings, 2 replies; 16+ messages in thread
From: Dale Stanbrough @ 2008-07-10  2:11 UTC (permalink / raw)


The purpose of an extended return is to create the values in-situ 
without copying. However an exception in the middle of the extended 
return seems to indicate otherwise (using Gnat).

Is this the expected behaviour, or is my understanding of the extended 
returns correct?

Thanks,

Dale


-------------------------------------------------
with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Returning_Large_Objects is

   type List is array (1..4) of Integer;
   
   
   function Extended_Return_Error (Raise_Exception : Boolean)
   return List
   is
   begin
      return L : List do
          L (1) := 1; L (2) := 2;
          if Raise_Exception then raise Constraint_Error; end if;
          L (3) := 3; L (4) := 4;
      end return;
   end;

   Destination : List;

   -------------------------------
   procedure Put (Item : List) is
   begin 
      for i in Item'range loop
         Put (Item (I));
      end loop;
      New_Line;
   end;

begin

   -- run normally, no exception

   Destination := (others => 0);

   Put (Destination);
   Destination := Extended_Return_Error (false);   
   Put (Destination);

   -- displays 1 2 3 4 as expected

   ---------------------------------
   -- run with exception in middle

   Destination := (others => 0);
   Put (Destination);
   begin
      Destination := Extended_Return_Error (true);
   exception
      when others => null;
   end;
   
   Put (Destination);
   -- displays 0 0 0 0, i expected 1 2 0 0

   -- the exception seems to have affected statements
   -- that precede it

   
end Returning_Large_Objects;

-- 
dstanbro@spam.o.matic.bigpond.net.au



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

end of thread, other threads:[~2008-07-11 14:24 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-10  2:11 Extended return question Dale Stanbrough
2008-07-10  7:18 ` Georg Bauhaus
2008-07-10  7:32   ` Dale Stanbrough
2008-07-10 15:24     ` Adam Beneschan
2008-07-10 23:56       ` Dale Stanbrough
2008-07-10 23:20     ` Randy Brukardt
2008-07-11  0:03       ` Adam Beneschan
2008-07-11  0:50         ` Robert A Duff
2008-07-10 14:37 ` Robert A Duff
2008-07-10 15:19   ` Adam Beneschan
2008-07-10 18:36     ` Dmitry A. Kazakov
2008-07-11  0:43       ` Robert A Duff
2008-07-11  7:39         ` Dmitry A. Kazakov
2008-07-11  9:06           ` christoph.grein
2008-07-11 14:24             ` Dmitry A. Kazakov
2008-07-11  0:29     ` Robert A Duff

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