comp.lang.ada
 help / color / mirror / Atom feed
From: Dale Stanbrough <MrNoSpam@bigpoop.net.au>
Subject: Extended return question
Date: Thu, 10 Jul 2008 02:11:41 GMT
Date: 2008-07-10T02:11:41+00:00	[thread overview]
Message-ID: <MrNoSpam-F95CC3.12114110072008@news-server.bigpond.net.au> (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



             reply	other threads:[~2008-07-10  2:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10  2:11 Dale Stanbrough [this message]
2008-07-10  7:18 ` Extended return question 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
replies disabled

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