Sequence points in a language with left to right evaluation order?
When evaluation order is specified as "left to right" and language is a (pseudo) C-like, which are开发者_运维技巧 the sequence points in the following examples?
int x = 1;
int z = x-- + x; // z = 1 + 0 or z = 1 + 1?
my_func(x++); // x incremented before or after my_func execution?
my_func(x++ + --x); // combining those above
A sequence point is what the language standard defines to be a sequence point. The answers I'm about to give apply to C, but another "C-like" language might very well define different sequence points and thus have different answers to those questions.
int z = x-- + x; // z = 1 + 0 or z = 1 + 1?
Since +
is not a sequence point in C, the result of the above statement is undefined.
my_func(x++); // x incremented before or after my_func execution?
x
is incremented before my_func
runs, but my_func
is called with the old value of x
as an argument.
my_func(x++ + --x); // combining those above
Undefined for the same reason as the first one.
精彩评论