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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: How to get nice with GNAT? Date: Sun, 23 Nov 2014 23:25:39 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <0d8452a9-68c9-4835-b6f3-17407132ca9f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 24 Nov 2014 06:25:27 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="6bb4f0a3c21c874c69dbcaa30e818f24"; logging-data="17692"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2qsS46snhBdMwdZh6IcsQ4I6Dt4jdddQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: <0d8452a9-68c9-4835-b6f3-17407132ca9f@googlegroups.com> Cancel-Lock: sha1:bF5YVXxozOcv1M3glkKh+MSYdVw= Xref: news.eternal-september.org comp.lang.ada:23682 Date: 2014-11-23T23:25:39-07:00 List-Id: On 11/23/2014 08:05 PM, brbarkstrom@gmail.com wrote: > > I don't think you'll get a sensible response when you try to set > Test(OK => True); or Test(OK => False) when the specification of > the procedure Test has OK as an "out" variable. It doesn't make > sense try to set this value as input to a variable that emerges from the procedure (Test). I think it's clear you have no idea what you're talking about. I set OK to True before calling Test so that I could demonstrate that Test did not modify that value. > The GNAT GPL GPS tool on my Ubuntu 14.04 LTS system returns the > two warnings: > 7.10 warning: assignment to pass-by-copy formal may have no effect > 7.10 warning: "raise" statement may result in abnormal return > (RM 6.4.1(17)) > > In other words, a programmer shouldn't expect a variable input to > an "out" variable in the interface specification to have any relation > to whatever is generated in the procedure that is called. Secondly, > an exception raised in the procedure test may result in an abnormal > return. This is hardly a clean piece of code. This warning is saying that the assignment to the formal parameter OK in Test (the "pass-by-copy formal") won't do anything because the formal is not copied back to the actual when the procedure propagates an exception. It has nothing to do with setting the variable OK to True. > When I run it, the output from the code does something that seems > to me to be an abnormal return. It returns the output "TRUE". Test does not return True. OK had the value True before the call, and it still has the value True after the call because the assignment to the formal parameter OK in True has no effect. This is what I was trying to demonstrate. > procedure Test (I : in Natural; > OK : out Boolean; > Err_Msg : out Vstring.Bounded_String) is > Max_I : Natural := 10; > I_Out_Of_Range : exception; > begin -- Test > OK := False; > Err_Msg := Vstring.To_Bounded_String("procedure Test was not initialized when this message was created."); > if I <= Max_I then > OK := True; > Err_Msg := Vstring.To_Bounded_String("In procedure Test, I as input : "); > Err_Msg := Vstring.Append(Err_Msg, Natural'image(I)); > Err_Msg := Vstring.Append(Err_Msg, " was less than or equal to "); > Err_Msg := Vstring.Append(Err_Msg, Natural'image(Max_I)); > else > raise I_Out_Of_Range; > end if; > exception > when I_Out_Of_Range => > Err_Msg := Vstring.To_Bounded_String("In procedure Test, I as input : "); > Err_Msg := Vstring.Append(Err_Msg, Natural'image(I)); > Err_Msg := Vstring.Append(Err_Msg, " was greater than "); > Err_Msg := Vstring.Append(Err_Msg, Natural'image(Max_I)); > Err_Msg := Vstring.Append(Err_Msg, " which raises the constraint 'I_Out_Of_Range'."); > when others => > Err_Msg := Vstring.To_Bounded_String("In procedure Test, something unexpected happened."); > end Test; This procedure never propagates an exception. It returns normally in all cases. As I said, you are not talking about exceptions in the calling code. You're talking about returning error codes and checking them after the call. This has all of the problems with returning error codes known from over 4 decades of using C. These problems led to the inclusion of exceptions in more modern languages; writing "C in Ada" is a step backwards. -- Jeff Carter "I'm particularly glad that these lovely children were here today to hear that speech. Not only was it authentic frontier gibberish, it expressed a courage little seen in this day and age." Blazing Saddles 88