[comp.lang.ada] Parameter modes

CONTR22@NOSC-TECR.ARPA (Dale Gaumer) (11/15/88)

     I would like to explore the possibility of using pass-by-reference for
non-scalar parameters with mode "out" or "in out". The LRM, in section 6.2(7),
states quite clearly that pass-by-copy is not required. However, the compilers
with which I am familiar use pass-by-copy. Since this is a serious performance
problem, I questioned several compiler vendors about why they chose to use
pass-by-copy.  The unanimous reply was, that the LRM requires pass-by-copy. 
     It was further explained to me that the LRM requires parameters to be
reset to the initial value when an exception occurs within the subprogram. And
the only way to ensure this result, is to use pass-by-copy. However the LRM,
in section 6.2(12), states that "the final value of an actual parameter of
such a type can be either its valued before the call or a value assigned to
the formal parameter during the execution of the subprogram". 
     A further explanation is that, an exception may occur during an
assignment of an array or record. If this were to occur, the assignment would
be incomplete. Therefore the result could contain garbage. If
pass-by-reference were used, this garbage would be returned as the actual
parameter. Therefore, since LRM 6.2(12) prohibits returning garbage as the
actual parameter, pass-by-copy must be used. However LRM section 5.2(3) states
that both sides of an assignment statement must be evaluated before the actual
assignment takes place. This would seems to preclude an exception occurring
during the actual assignment. 
     It seems to me that the LRM went to great lengths to make
pass-by-reference a legal implementation, for parameters of mode "out" or "in
out", which are array or record types. However this facility is not being used
by many compiler vendors. 


                                          David Brookman
                                          Magnavox Electronic Systems Company
                                          1313 Production Road
                                          Fort Wayne, IN 46808
                                          November 14, 1988

firth@sei.cmu.edu (Robert Firth) (11/18/88)

In article <8811151407.AA10227@ajpo.sei.cmu.edu> CONTR22@NOSC-TECR.ARPA (Dale Gaumer) writes:

>     I would like to explore the possibility of using pass-by-reference for
>non-scalar parameters with mode "out" or "in out".
...
>     It seems to me that the LRM went to great lengths to make
>pass-by-reference a legal implementation, for parameters of mode "out" or "in
>out", which are array or record types.

I can confirm, for what it's worth, that it was the conscious intent of
the language designers to permit non-scalar (and non-access) parameters
to be passed by either copy or reference, at the option of the implementor.

If there is anything currently in the RM that prohibits that, I'm not aware
of it; should you know of any such statement, please bring it to the
attention of the Ada Board, so that they can fix it.

murphy@beatnix.UUCP (Michael Murphy) (11/22/88)

I'm rather baffled by what you are saying.  The LRM does indeed allow you
to pass parameters by reference, and in fact I know of some (validated) 
compilers that do.  For example, all Verdix-based compilers can pass
parameters by reference.  I suspect that you have simply heard some lame
excuses from some compiler vendors who didn't go to the trouble of
implementing pass-by-reference (perhaps I'm being too harsh here,
but if so then can someone post an example that shows why you cannot
use pass-by-reference?).

-- michael murphy
-- UUCP: {uunet|sun}!elxsi!elk!murphy
-- AT&T: 408-942-0900