comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: How to get nice with GNAT?
Date: Sun, 23 Nov 2014 23:25:39 -0700
Date: 2014-11-23T23:25:39-07:00	[thread overview]
Message-ID: <m4uj0l$h8s$1@dont-email.me> (raw)
In-Reply-To: <0d8452a9-68c9-4835-b6f3-17407132ca9f@googlegroups.com>

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


  reply	other threads:[~2014-11-24  6:25 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-21 11:41 How to get nice with GNAT? Natasha Kerensikova
2014-11-21 12:42 ` Björn Lundin
2014-11-21 22:55 ` Randy Brukardt
2014-11-21 23:13   ` Björn Lundin
2014-11-22  9:45   ` How to get nice traceback " Natasha Kerensikova
2014-11-22  9:57     ` Dmitry A. Kazakov
2014-11-24 22:35     ` Randy Brukardt
2014-11-22 10:11 ` How to get nice " gautier_niouzes
2014-11-22 10:40   ` Natasha Kerensikova
2014-11-22 22:44 ` brbarkstrom
2014-11-22 23:24   ` Jeffrey Carter
2014-11-23 18:06   ` Björn Lundin
2014-11-23 16:13 ` brbarkstrom
2014-11-23 16:18   ` J-P. Rosen
2014-11-23 17:02   ` Jeffrey Carter
2014-11-23 17:41 ` brbarkstrom
2014-11-23 19:22   ` Simon Wright
2014-11-23 20:49   ` Jeffrey Carter
2014-11-24  3:05     ` brbarkstrom
2014-11-24  6:25       ` Jeffrey Carter [this message]
2014-11-24 14:39         ` brbarkstrom
2014-11-24 17:42       ` Dennis Lee Bieber
2014-11-25 13:45         ` brbarkstrom
2014-11-25 15:07           ` ake.ragnar.dahlgren
2014-11-25 15:51             ` brbarkstrom
2014-11-25 16:52             ` Jeffrey Carter
2014-11-25 19:18             ` G.B.
2014-11-25 20:47               ` brbarkstrom
2014-11-25 22:12             ` Randy Brukardt
2014-11-25 23:30               ` Simon Wright
2014-11-26  1:25                 ` G.B.
2014-11-26  7:35                   ` Simon Wright
2014-11-26 11:55                     ` Georg Bauhaus
2014-11-26 13:06                       ` Dmitry A. Kazakov
2014-11-26 13:36                         ` brbarkstrom
2014-11-26 21:27                         ` Randy Brukardt
2014-11-26 22:38                           ` brbarkstrom
2014-11-27  9:01                             ` Dmitry A. Kazakov
2014-11-27 13:53                               ` brbarkstrom
2014-11-27 17:19                                 ` Dmitry A. Kazakov
2014-12-01 22:25                                   ` Randy Brukardt
2014-12-02  8:42                                     ` Dmitry A. Kazakov
2014-12-03 21:41                                       ` Randy Brukardt
2014-12-06 12:02                                         ` Dmitry A. Kazakov
2014-12-08 22:45                                           ` Randy Brukardt
2014-12-09  8:51                                             ` Dmitry A. Kazakov
2014-12-09 23:14                                               ` Brad Moore
2014-12-09 17:59                                                 ` Dmitry A. Kazakov
2014-11-27  8:52                           ` Dmitry A. Kazakov
2014-11-26  6:18                 ` J-P. Rosen
2014-11-26  7:37                   ` Simon Wright
2014-11-26  8:41               ` Dmitry A. Kazakov
2014-11-25 18:33           ` Dennis Lee Bieber
2014-11-26  1:27             ` Dennis Lee Bieber
2014-11-26  3:29               ` brbarkstrom
2014-11-23 18:55 ` brbarkstrom
2014-11-23 19:30 ` brbarkstrom
2014-11-23 22:38   ` Simon Wright
2014-11-24  2:47     ` brbarkstrom
replies disabled

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