Is this code well-defined?
Posted
by
Nawaz
on Stack Overflow
See other posts from Stack Overflow
or by Nawaz
Published on 2011-01-17T03:17:37Z
Indexed on
2011/01/17
3:53 UTC
Read the original article
Hit count: 307
This code is taken from a discussion going on here.
someInstance.Fun(++k).Gun(10).Sun(k).Tun();
Is this code well-defined? Is ++k
Fun() evaluated before k
in Sun()?
What if k
is user-defined type, not built-in type? And in what ways the above function calls order is different from this:
eat(++k);drink(10);sleep(k);
As far as I can say, in both situations, there exists a sequence point after each function call. If so, then why can't the first case is also well-defined like the second one?
Section 1.9.17 of the C++ ISO standard says this about sequence points and function evaluation:
When calling a function (whether or not the function is inline), there is a sequence point after the evaluation of all function arguments (if any) which takes place before execution of any expressions or statements in the function body. There is also a sequence point after the copying of a returned value and before the execution of any expressions outside the function.
© Stack Overflow or respective owner