Bjarne Stroustrup's C++ Style and Technique FAQ里面有一段:
What's the value of i++ + i++?
It's undefined. Basically, in C and C++, if you read a variable twice in an expression where you also write it, the result is undefined. Don't do that. Another example is:
v[i] = i++;
Related example:
f(v[i],i++);
Here, the result is undefined because the order of evaluation of function arguments are undefined.
Having the order of evaluation undefined is claimed to yield better performing code. Compilers could warn about such examples, which are typically subtle bugs (or potential subtle bugs). I'm disappointed that after decades, most compilers still don't warn, leaving that job to specialized, separate, and underused tools.
[翻译]
i++ + i++ 的值是多少?
未定义。基本上,无论 C 还是 C++,如果你在同一个表达式中两次读取同一个变量,并且还对该变量进行写操作,那么结果就是未定义的。不要这么干。还有个例子是: