Return to Parameter-Passing Methods

Implementation Methods:

Pass-By-Value     (In mode)

     Actual parameter (argument) is used to initialize the formal parameter (parameter).
     Implemented by actual data transfer (physically copy)
     It takes a lot of space.

Pass-By-Result    (Out mode)

     Value determined in subprogram is returned to actual parameter.
     Troubles (page 340)

          There can be an actual parameter collision:

               In function call:     sub(p1, p1)
               In function definition:    there are two different parameter's names, void sub(int s1, int s2)

                    s1 --> p1
                    s2 --> p1

               One of them will be overwritten.

Pass-By-Value-Result  (In-Out mode)

     It is a combination of above two.

Pass-By-Reference    (In-Out mode)

     No duplicate space
     No copying
     Access to formal parameters is slow
     If only one-way communication is needed, this is not safe
     Allow for creation of aliases

Pass-By-Name    (In-Out mode)

     The actual parameter is textually substituted for corresponding formal parameter in all occurrences in the subprogram.
     If the actual parameter is a constant, then this is equivalent to Pass-By-Value
     If the actual parameter is a scalar, then this is equivalent to Pass-By-Reference.

     Other methods:  formal parameters are bound to actual values or addresses at the time of the subprogram call.
     This method: formal parameter is bound to an access method at the time of the subprogram call,
                         but the actual binding to a value or an address is delayed until the formal parameter is assigned or referenced.

See the following example from page 364 of second edition:
¡@
procedure BIGSUB;
   integer GLOBAL;
   integer array LIST[1:2];
   procedure SUB(PARAM);
      integer PARAM;
      begin
      PARAM := 3;
      GLOBAL := GLOBAL + 1;
      PARAM := 5
      end;
   begin
   LIST[1] := 2;
   LIST[2] := 2;
   GLOBAL := 1;
   SUB(LIST[GLOBAL])
   end;
   

After execution, the array LIST has the values 3 and 5.
 
It is used at compile time by macros in assembly languages and the generic parameters of the generic subprograms in C++, Java 5.0, and C# 2005