Implementation Models of Parameter Passing
There are five different implementation models of parameter passing. They are Pass-by-Value, Pass-by-Result, Pass-by-Value-Result, Pass-by-Reference, and Pass-by-Name.
Pass-by-Value means that the value of the actual parameter is used to initialize the formal parameter. The formal parameter then acts as a local variable in the subprogram. This implements in-mode semantics.
Advantages: Is very fast for scalars (in linkage cost and access time)
Disadvantages: if copies are used, additional storage required
Pass-by-Result is used for out-mode parameters. When Pass-by-Result is used, no value is transmitted to the subprogram. The corresponding formal parameter acts as a local variable, but before control is transferred back to the caller, its value is transmitted back to the caller’s actual parameter. This actual parameter must be variable.
Advantages: Is very fast for scalars (in linkage cost and access time)
Disadvantages: there can be a parameter collision
Pass-by-Value-Result (or Pass-By-Copy) is used for inout-mode parameters when actual values are copied. It is a combination of pass-by-value and pass-by-result. The value of the actual parameter is used to initialize the formal parameter. The formal parameter then acts as a local variable.
Advantages: same as Pass-by-Reference
Disadvantages: same as Pass-by-Reference
Pass-by-Reference is another implementation model for inout-mode parameters. Instead of copying data values back and forth, it transmits an access path (usually an address) to the called subprogram. This access path goes to the cell storing the actual parameter. The actual parameter is shared with the called subprogram.
Advantages: the passing process is efficient
Disadvantages: Access to formal parameters is slower, aliases can be created, accidental changes can be made to the actual parameter
Pass-by-Name is an inout-mode parameter transmission method. It does not correspond to a single implementation model. When using passing-by-name, the actual parameter is substituted for the formal parameter in all its occurrences in the subprogram.
Advantages: none, kinda
Disadvantages: A ton. Inefficient and super complex
There you go! Now you know everything you need to know about parameter-passing!
-Data



















