Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Extended return...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 5805 of 5930
Post > Topic >>

Extended return question

by Dale Stanbrough <MrNoSpam@[EMAIL PROTECTED] > Jul 10, 2008 at 02:11 AM

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@[EMAIL PROTECTED]

 




 16 Posts in Topic:
Extended return question
Dale Stanbrough <MrNoS  2008-07-10 02:11:41 
Re: Extended return question
Georg Bauhaus <see.rep  2008-07-10 09:18:59 
Re: Extended return question
Dale Stanbrough <MrNoS  2008-07-10 07:32:21 
Re: Extended return question
"Randy Brukardt"  2008-07-10 18:20:11 
Re: Extended return question
Robert A Duff <bobduff  2008-07-10 10:37:55 
Re: Extended return question
Adam Beneschan <adam@[  2008-07-10 08:19:41 
Re: Extended return question
"Dmitry A. Kazakov&q  2008-07-10 20:36:51 
Re: Extended return question
Robert A Duff <bobduff  2008-07-10 20:43:09 
Re: Extended return question
"Dmitry A. Kazakov&q  2008-07-11 09:39:50 
Re: Extended return question
Robert A Duff <bobduff  2008-07-10 20:29:31 
Re: Extended return question
Adam Beneschan <adam@[  2008-07-10 08:24:45 
Re: Extended return question
Dale Stanbrough <MrNoS  2008-07-10 23:56:53 
Re: Extended return question
Adam Beneschan <adam@[  2008-07-10 17:03:31 
Re: Extended return question
Robert A Duff <bobduff  2008-07-10 20:50:25 
Re: Extended return question
christoph.grein@[EMAIL PR  2008-07-11 02:06:17 
Re: Extended return question
"Dmitry A. Kazakov&q  2008-07-11 16:24:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 9:04:34 CDT 2008.