I wonder, is the marked line in the below code correct. Because in this line the result of the function is assigned to the static variable prevRecCallResult
(I'll call it "plain assignment"), which is changed inside this function (I'll call it "inside assignment").
Is it guaranteed, that the "inside assignment" is done, when the "plain assignment" executes?
int f(int _n)
{
if (_n >= 1)
{
static int prevRecCallResult;
prevRecCallResult = f(_n - 1); //<-- Is this line Ok?
return prevRecCallResult + 1;
}
else
return _n;
}
I know, the standard says, that a sequence point occurs:
At a function return, after the return value is copied into the calling context.
, but I'm not sure, this is the answer to my question.
Update:
Considering replies I've received, I should clarify my question:
It's essence is: Is it true, that the prevRecCallResult
is not in use by the assignment expression (in marked line) (i.e. is not occupied by it) until f(_n - 1)
is finished? (And thus, until this moment, prevRecCallResult
is absolutely free for any assignments inside f(_n - 1)
?)