Call By Value Result

A ParameterPassing mode, used in AdaLanguage to handle "IN OUT" parameters. In CallByValueResult, the actual parameter supplied by the caller is copied into the callee's formal parameter; the function is run; and the (possibly modified) formal parameter is then copied back to the caller. This allows a function to modify the state of its caller, similar to what you get with CallByReference. The (semantic) differences between CallByReference and CallByValueResult are:

 void outer (void) 
 {
      int a = 5, b = 7;

void inner (IN OUT int c; REF int d) { printf ("a: %d b: %d c: %d d: %d\n", a,b,c,d); a = 0; b = 9; c = 4; d = 6; printf ("a: %d b: %d c: %d d: %d\n", a,b,c,d); }

inner(a,b); printf ("a: %d b: %d\n",a,b); }
The results of this should be

 a: 5 b: 7 c: 5 d: 7
 a: 0 b: 6 c: 4 d: 6  // d and b are aliases, so b=9 got clobbered
 a: 4 b: 6            // a replaced with value of c on function exit.
Some languages allow CallByReference as an optimization of CallByValueResult if it can be shown that the two (due to lack of aliasing, etc.) are semantically equivalent.


See also ParameterPassing, CallByValue, CallByReference, CallByThunk


CategoryLanguageFeature


EditText of this page (last edited October 22, 2014) or FindPage with title or text search