In parameter-passing by result, when the formal parameter value is assigned to the actual one?
As title, just after return statement?
int x = 1;
function F(ref int y) { y = y + AnotherF(x); }
function A开发者_开发知识库notherF(result z)
{
z = null;
return (-1);
}
F(x); print(x); // prints 0 or null?
Answer to myself: The function AnotherF returns -1. The just before destroying its record (and thus before passing the control back to F), the value of z is assigned back to the actual parameter (y). After assigning null to x then F continues to evaluate y = 1 + (-1) = 0. Then x is 0.
精彩评论