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:
- No alias is created between the formal and actual parameters. If lexical scoping is used, the difference can be apparent. Consider the following snippets in a mythical C/Ada-ish hybrid (LexicalScoping is present):
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