From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f8a440310f7f2e02,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!nlpi057.nbdc.sbc.com!prodigy.net!newsfeed-00.mathworks.com!lon-transit.news.telstra.net!lon-in.news.telstra.net!news.telstra.net!news-server.bigpond.net.au!53ab2750!not-for-mail From: Dale Stanbrough Newsgroups: comp.lang.ada Subject: Extended return question User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X) Message-ID: Date: Thu, 10 Jul 2008 02:11:41 GMT NNTP-Posting-Host: 58.161.16.225 X-Complaints-To: abuse@bigpond.net.au X-Trace: news-server.bigpond.net.au 1215655901 58.161.16.225 (Thu, 10 Jul 2008 12:11:41 EST) NNTP-Posting-Date: Thu, 10 Jul 2008 12:11:41 EST Organization: BigPond Internet Services Xref: g2news1.google.com comp.lang.ada:1073 Date: 2008-07-10T02:11:41+00:00 List-Id: 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