* semantics of exception when exiting a procedure
@ 1990-08-15 9:29 Daniel Wengelin
1990-08-15 17:01 ` Brian Hanafee
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Daniel Wengelin @ 1990-08-15 9:29 UTC (permalink / raw)
Question:
What are the semantics when a procedure with out parameters is
exited by an exception. Can the out parameters be used, if they
have been assigned prior to the exception ?
Example>
procedure X(P1,P2,P3:out...)is
..
P1:=....
if ... raise E1;....
P2:=....
if .... raise E2;....
P3:=...
end X;
.....
X(P1,P2,P3);
Do_Something_With(P1,P2,P3);
exception
when E1=>Do_Something_With(P1);
when E2 => Do_Something_With(P1,P2);
..
It would appear that the above code should work, but it does seem
a bit risky.
I would very much appreciate a LRM ref on this one !
/dw/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: semantics of exception when exiting a procedure
1990-08-15 9:29 semantics of exception when exiting a procedure Daniel Wengelin
@ 1990-08-15 17:01 ` Brian Hanafee
1990-08-15 17:08 ` Jerry Callen
1990-08-15 17:16 ` Fred Stluka
2 siblings, 0 replies; 4+ messages in thread
From: Brian Hanafee @ 1990-08-15 17:01 UTC (permalink / raw)
In article <1616@kuling.UUCP> daniel@mizar.docs.uu.se (Daniel Wengelin) writes:
>Question:
>What are the semantics when a procedure with out parameters is
>exited by an exception. Can the out parameters be used, if they
>have been assigned prior to the exception ?
[example deleted]
>I would very much appreciate a LRM ref on this one !
>
>/dw/
Try LRM 6.2/6, "...the effects are achieved by copy...after *normal*
completion of the subprogram body, if the mode is in out or out, the
value of the formal parameter is copied back into the associated
actual parameter."
This seems to say that the out parameters should *not* be used if
the procedure exited by exception. 6.2/12 and 6.4.1/7 give some
(vague) hints about why it might be specified this way.
Brian Hanafee
Advanced Decision Systems
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: semantics of exception when exiting a procedure
1990-08-15 9:29 semantics of exception when exiting a procedure Daniel Wengelin
1990-08-15 17:01 ` Brian Hanafee
@ 1990-08-15 17:08 ` Jerry Callen
1990-08-15 17:16 ` Fred Stluka
2 siblings, 0 replies; 4+ messages in thread
From: Jerry Callen @ 1990-08-15 17:08 UTC (permalink / raw)
In article <1616@kuling.UUCP> daniel@mizar.docs.uu.se (Daniel Wengelin) writes:
>Question:
>What are the semantics when a procedure with out parameters is
>exited by an exception. Can the out parameters be used, if they
>have been assigned prior to the exception ?
>
> [example deleted]
This whole area is described in something less than lucid detail in section
11.6 (Exceptions and Optimization). The example and comments in paragraphs
10 and 11 are helpful.
Basically, if the exception is raised in the body, you can depend only upon
initializations done in the declarations. In other words, the value of
out parameters is undefined.
-- Jerry Callen
jcallen@encore.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: semantics of exception when exiting a procedure
1990-08-15 9:29 semantics of exception when exiting a procedure Daniel Wengelin
1990-08-15 17:01 ` Brian Hanafee
1990-08-15 17:08 ` Jerry Callen
@ 1990-08-15 17:16 ` Fred Stluka
2 siblings, 0 replies; 4+ messages in thread
From: Fred Stluka @ 1990-08-15 17:16 UTC (permalink / raw)
In article <1616@kuling.UUCP> daniel@mizar.docs.uu.se (Daniel Wengelin) writes:
> Question:
> What are the semantics when a procedure with out parameters is
> exited by an exception. Can the out parameters be used, if they
> have been assigned prior to the exception ?
> ...
> I would very much appreciate a LRM ref on this one !
6.2 Formal Parameter Modes
...
For a scalar parameter, the above effects are achieved by copy: at the
start of each call, if the mode is in or in out, the value of the actual
parameter is copied into the associated formal parameter; then after
normal completion of the subprogram body, if the mode is in out or out, the
value of the formal parameter is copied back into the associated actual
parameter. For a parameter whose type is an access type, copy-in is used
for all three modes, and copy-back for the modes in out and out.
For a parameter whose type is an array, record, or task type,
... an implementation may achieve
these effects by reference, that is, by arranging that every use of the
formal parameter (to read or to update its value) be treated as a use of
the associated actual parameter, throughout the execution of the subprogram
call. The language does not define which of these two mechanisms is to be
adopted for parameter passing, nor whether different calls to the same
subprogram are to use the same mechanism. The execution of a program is
erroneous if its effect depends on which mechanism is selected by the
implementation.
...
Notes:
For parameters of array and record types, the parameter passing rules have
these consequences:
- If the execution of a subprogram is abandoned as a result of an
exception, the final value of an actual parameter of such a type can
be either its value before the call or a value assigned to the formal
parameter during the execution of the subprogram.
--Fred
Fred Stluka Internet: stluka@software.org
Software Productivity Consortium UUNET: ...!uunet!software!stluka
2214 Rock Hill Rd, Herndon VA 22070
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1990-08-15 17:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-08-15 9:29 semantics of exception when exiting a procedure Daniel Wengelin
1990-08-15 17:01 ` Brian Hanafee
1990-08-15 17:08 ` Jerry Callen
1990-08-15 17:16 ` Fred Stluka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox