comp.lang.ada
 help / color / mirror / Atom feed
From: jakrzy@ss2.magec.com (James A. Krzyzanowski)
Subject: Re: Call by reference vs. call by value
Date: 1996/07/20
Date: 1996-07-20T00:00:00+00:00	[thread overview]
Message-ID: <DuutM7.7H7@most.fw.hac.com> (raw)
In-Reply-To: 31F10E50.726@egr.uri.edu


Christopher Felaco (felaco@egr.uri.edu) wrote:
: I came across a problem with a procedure that resembled the following:

: type Simple_Vector is array (1 .. 2) of Float;

: procedure Vector_Manipulation (X : in Simple_Vector;
:                                Y : out Simple_Vector) is
: begin

:     Y (1) := X (1) + X (2);
:     Y (2) := X (1) * X (2);

: end Vector_Manipulation;

: I was told that calling this procedure with the same in and out
: parameters as follows would give unexpected results:

:     Vector_Manipulation (X => Test_Vector, Y => Text_Vector);
                                                    ^
                                                  Test_Vector

I think you have a typo and meant that both actual parameters were the
same variable.  I just recently answered this exact question for a
colleague.  Here is a copy of my reply...

I don't know if this is it, but check out LRM 6.2...

paragraph (1) - "...The value of a variable is said to be updated when an
assignment is performed to the variable, and also (indirectly) when the
variable is used as actual parameter of a subprogram call...that updates
its value"

paragraph (7) - "...an implementation may achieve these effects by
reference, that is, by arranging that every use of a 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."

Since the out parameter is the same variable as the in parameter, if the
compiler writers chose to use "reference" for both the in and out parameter
then the value of the in parameter would change everytime the out parameter
changed.  Sounds hokie but they could probably get away with it with the
language referenced above.

--
Not necessarily the opinion of the company...
--
---------------------------------------------------------------------------
         James A. Krzyzanowski - Senior Software Engineer - AFATDS
Magnavox Electronic Systems Company * Fort Wayne, IN 46808 * (219) 429-6446
Internet: jakrzy@most.fw.hac.com * AOL: JimShiz@AOL.com * MOST: jakrzy@most
     "I'd rather be right than politically correct !!!" - Rush is Right
---------------------------------------------------------------------------




  reply	other threads:[~1996-07-20  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-20  0:00 Call by reference vs. call by value Christopher Felaco
1996-07-20  0:00 ` James A. Krzyzanowski [this message]
1996-07-20  0:00   ` Robert Dewar
1996-07-20  0:00 ` Robert Dewar
1996-07-21  0:00   ` Robert A Duff
1996-07-21  0:00     ` Robert Dewar
1996-07-22  0:00       ` Robert A Duff
1996-07-23  0:00         ` Peter Amey
1996-07-23  0:00           ` Robert Dewar
1996-07-24  0:00             ` Robert A Duff
1996-07-23  0:00           ` Robert A Duff
1996-07-27  0:00             ` Peter Morris
1996-07-28  0:00               ` Robert A Duff
1996-07-24  0:00           ` Richard A. O'Keefe
1996-07-22  0:00   ` Felaco
1996-07-22  0:00     ` Robert Dewar
1996-07-22  0:00     ` Robert A Duff
1996-07-30  0:00       ` Richard A. O'Keefe
1996-07-22  0:00   ` Karl Cooper {46901}
1996-07-22  0:00     ` Robert Dewar
1996-07-30  0:00   ` Felaco
1996-07-31  0:00     ` Robert A Duff
1996-08-02  0:00     ` Robert Dewar
1996-08-03  0:00     ` JP Thornley
1996-08-05  0:00       ` Roderick Chapman
1996-07-21  0:00 ` Robert A Duff
1996-07-21  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1996-07-25  0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-07-26  0:00 ` Peter Amey
replies disabled

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