comp.lang.ada
 help / color / mirror / Atom feed
From: brbarkstrom@gmail.com
Subject: Re: How to get nice with GNAT?
Date: Tue, 25 Nov 2014 05:45:45 -0800 (PST)
Date: 2014-11-25T05:45:45-08:00	[thread overview]
Message-ID: <8194a204-7b15-463d-a2fd-4d3ba342fe97@googlegroups.com> (raw)
In-Reply-To: <jtq67a5ffb7fm44joao6a7nbvav7mdq29o@4ax.com>

On Monday, November 24, 2014 12:42:23 PM UTC-5, Dennis Lee Bieber wrote:
> On Sun, 23 Nov 2014 19:05:18 -0800 (PST), brbarkstrom declaimed
> the following:
> 
> 
> >
> >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. 
> >
> >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".
> >The output claims that "the process terminated successfully, ...".  
> >It certainly isn't the expected behavior in a reasonable reading of the 
> >procedure text.  Rather it suggests that the compiler completely ignored
> >whatever went on in the procedure.
> >
> 
> 	I would interpret it to mean that the raise statement aborted the
> function "test" before the copying of the "FALSE" value into the return
> structure on the stack, so the main procedure never sees the value change.
> 
> 	If scalar's are handled as locals that are copied from the passed
> parameters on input and then copied back upon (normal) exit -- this makes
> sense.
> 
> 	The last paragraph of the (2005) Reference Manual, section 6.4.1
> Parameter Associations reads:
> 
> After normal completion and leaving of a subprogram, for each IN OUT or OUT
> parameter that is passed by copy, the value of the formal parameter is
> converted to the subtype of the variable given as the actual parameter and
> assigned to it.
> 
> 	Note that: "after normal completion and leaving ... and assigned to
> it".
> 
> 	The raise is not "normal completion", and thereby may not perform the
> "assign".
> -- 
> 	Wulfraed                 Dennis Lee Bieber         AF6VN

If an exception is raised, section 11.4 of the RM comes into play.  11.4(1)
says that when an exception is raised, normal program execution is abandoned
and control is transferred to an applicable exception handler, if any.  Note
also section 11.4(7) which allows an exception handler to carry on assigning
variables, including ones that can be passed out.  When the exception handler
works, it lowers the exception and prevents propagation to the calling
procedure.  Thus, it is perfectly acceptable for the handler to assign
an "out" variable, which will be passed out.

In other words,

1) No exception is raised: pass-by-copy variables appear in the calling
procedure with the last value assigned before the called procedure exits;
there is no exception propagated back to the caller.

2) An exception is raised without an exception handler in the called procedure:
the exception is propagated back to the caller.  I believe a pass-by-copy
parameter that is an "out" parameter in the interface propagates out to the
caller with the last assigned value.

3) An exception is raised with an exception handler in the called procedure:
the exception is lowered and not propagated to the caller.  The exception
handling code can assign a legal value to an "out" parameter and it will appear
in the calling procedure with that value.

4) An exception is raised with an exception handler in the called procedure,
but the exception handler contains a raise; statement: the exception is reraised
and will be propagated back to the caller.  The exception handling code can
assign a legal value to an "out" parameter before the exception is re-raised,
in which case the new assignment will appear in the calling procedure.

5) The Exceptions Package of part 11.4.1 offers ready-made functions 
and procedures that can reduce programming effort.

These behaviors are consistent with what I've observed in the execution of the
compiled versions of the code I provided in previous posts.  I think the only
question about whether different compilers would implement this behavior is
item 2), although I have not been able to find a clear statement in RM as
to whether not passing back a pass-by-copy value is left to the implementer
in the event of the exception being raised.

Bruce B.


  reply	other threads:[~2014-11-25 13:45 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
2014-11-24 14:39         ` brbarkstrom
2014-11-24 17:42       ` Dennis Lee Bieber
2014-11-25 13:45         ` brbarkstrom [this message]
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