user-0 提问: 和同学打赌该语法是否有歧义，但是没编译器试，特来寻求答案。

回复:
user: user-1
content: vs2012的结果 也是1和0 我勒个去 的确不同编译器不同实现 而且重载++还是得到可能错误的结果

user: user-1
content: 明天在vs上试试 感觉被骗了

user: user-1
content: n=0; s=n++ + n++ ; tcc结果s=1 gcc和g++结果都是s=0 这结果真出乎我意料！！！ 本来认为c++的结果一定是1的 比如，你完成了一个CInt类 #include <iostream> using namespace std ;  class CInt { private :   int i ; public :   CInt () {   }   CInt (int i) {     this->i = i ;   }   CInt operator++ (int) {     int t = i++ ;     return CInt (t) ;   }   friend CInt operator+ (CInt a ,CInt b) {     int t = a.i + b.i ;     return CInt (t) ;   }   friend inline ostream &operator<< (ostream &os ,CInt &a) {     return os << a.i ;   } } ;  int main () {   CInt a = 0 ;   CInt b = a++ + a++ ;   int c = 0 ;   int d = c++ + c++ ;   cout << b << endl ;   cout << d << endl ;   return 0 ; } 输出是1和0！！！ 这意味着重载++将是很不安全的！！！

user: user-2
content: 即便结果是确定的，出这种题的人也是傻逼

user: user-3
content: 不写这种代码 也不研究它

user: user-4
content: 古往今来都不缺孔乙己式的学究。

user: user-5
content: C99语法归约过程  #include <stdio.h>  int main(void) { 	s3=a++*a+b+c*a*++b/4; }   归约栈   curr[6]: int  next[75]: main   type-specifier  declaration-specifiers   curr[75]: main  next[69]: (   declaration-specifiers direct-declarator   curr[69]: (  next[1]: void    curr[1]: void  next[70]: )   declaration-specifiers direct-declarator ( type-specifier  declaration-specifiers direct-declarator ( declaration-specifiers  declaration-specifiers direct-declarator ( parameter-declaration  declaration-specifiers direct-declarator ( parameter-list  declaration-specifiers direct-declarator ( parameter-type-list   curr[70]: )  next[67]: {   declaration-specifiers direct-declarator  declaration-specifiers declarator   curr[67]: {  next[75]: s3    curr[75]: s3  next[55]: =   declaration-specifiers declarator { primary-expression  declaration-specifiers declarator { postfix-expression  declaration-specifiers declarator { unary-expression   curr[55]: =  next[75]: a   declaration-specifiers declarator { unary-expression assignment-operator   curr[75]: a  next[30]: ++   declaration-specifiers declarator { unary-expression assignment-operator primary-expression  declaration-specifiers declarator { unary-expression assignment-operator postfix-expression   curr[30]: ++  next[35]: *   declaration-specifiers declarator { unary-expression assignment-operator postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator unary-expression  declaration-specifiers declarator { unary-expression assignment-operator cast-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression   curr[35]: *  next[75]: a    curr[75]: a  next[38]: +   declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * primary-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * unary-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * cast-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression   curr[38]: +  next[75]: b    curr[75]: b  next[38]: +   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression   curr[38]: +  next[75]: c    curr[75]: c  next[35]: *   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression   curr[35]: *  next[75]: a    curr[75]: a  next[35]: *   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression   curr[35]: *  next[38]: +    curr[38]: +  next[75]: b   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-operator   curr[75]: b  next[36]: /   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-operator primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-operator postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-operator unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-operator cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression   curr[36]: /  next[76]: 4    curr[76]: 4  next[74]: ;   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression  declaration-specifiers declarator { unary-expression assignment-operator shift-expression  declaration-specifiers declarator { unary-expression assignment-operator relational-expression  declaration-specifiers declarator { unary-expression assignment-operator equality-expression  declaration-specifiers declarator { unary-expression assignment-operator AND-expression  declaration-specifiers declarator { unary-expression assignment-operator exclusive-OR-expression  declaration-specifiers declarator { unary-expression assignment-operator inclusive-OR-expression  declaration-specifiers declarator { unary-expression assignment-operator logical-AND-expression  declaration-specifiers declarator { unary-expression assignment-operator logical-OR-expression  declaration-specifiers declarator { unary-expression assignment-operator conditional-expression  declaration-specifiers declarator { unary-expression assignment-operator assignment-expression  declaration-specifiers declarator { assignment-expression  declaration-specifiers declarator { expression   curr[74]: ;  next[68]: }   declaration-specifiers declarator { expression-statement  declaration-specifiers declarator { statement  declaration-specifiers declarator { block-item  declaration-specifiers declarator { block-item-list   curr[68]: }  next[0]: NULL   declaration-specifiers declarator compound-statement  function-definition  function-definition-list  translation-unit    按照归约顺序求值，绝对正确！

user: user-6
content: 引用 11 楼 starytx 的回复:又是这样的问题，就没有停止的时候。不要写自己无法预料结果的代码问题就在这里  总有一下新人以为 这样的代码结果是可以预料的 ......

user: user-7
content: 又是这样的问题，就没有停止的时候。不要写自己无法预料结果的代码

user: user-8
content: 在一个表达式计算中，存在++/--这样会修改变量本身的值的情况称作副效应(Side effect)，副效应和其他运算符发生的先后顺序是由序列点(Sequence Point)决定的。到达一个序列点时，之前所有的运算和副效应都应该计算完毕，而之后所有的运算和副效应都没有进行计算。（更具体的说明可以看c标准5.1.2.3节） Sequence Point的定义参见c标准的Annex C。只有一个完整的表达式结束才是一个序列点，在一个表达式内部是没有序列点的。因此在这个例子中，后缀++运算修改值本身到底发生在什么时候，属于标准未定义的行为，在不同的编译器中会有不同的实现，也就是或这个表达式的计算结果在不同编译器下会不同。 结论正如LZ期望的那样：出这个题目的人是NC。

user: user-9
content: 看着好纠结啊这个表达式

user: user-10
content: 其实我关注的这个：“但是没有编译器试“。  亲，既然你能在CSDN发帖子，就说明你能上网；  既然你能上网，为什么不能登录一个可以在线编译C++的网站编译运行一下呢？  即使你手头没有这样的网站，下一个gcc貌似也行啊，亲。

user: user-11
content: 用编译器也测试不出正确的结果。

user: user-12
content: 赌什么？多赌点。让你同学把全部身家压上。这赌局你稳赢了。

user: user-13
content: 这种东西研究有何意义？

user: user-14
content: 同的编译器会得到不同的结果 11121

user: user-14
content: bu同的编译器会得到不同的结果

user: user-15
content: 不同的编译器会得到不同的结果

user: user-16
content: 不同的编译器，结果可能就不同，另，题目中少了基础运算符

user: user-5
content: 修正，上面我的回复，贴错喽这个是对应的   curr[6]: int  next[75]: main   type-specifier  declaration-specifiers   curr[75]: main  next[69]: (   declaration-specifiers direct-declarator   curr[69]: (  next[1]: void    curr[1]: void  next[70]: )   declaration-specifiers direct-declarator ( type-specifier  declaration-specifiers direct-declarator ( declaration-specifiers  declaration-specifiers direct-declarator ( parameter-declaration  declaration-specifiers direct-declarator ( parameter-list  declaration-specifiers direct-declarator ( parameter-type-list   curr[70]: )  next[67]: {   declaration-specifiers direct-declarator  declaration-specifiers declarator   curr[67]: {  next[75]: s3    curr[75]: s3  next[55]: =   declaration-specifiers declarator { primary-expression  declaration-specifiers declarator { postfix-expression  declaration-specifiers declarator { unary-expression   curr[55]: =  next[75]: a   declaration-specifiers declarator { unary-expression assignment-operator   curr[75]: a  next[30]: ++   declaration-specifiers declarator { unary-expression assignment-operator primary-expression  declaration-specifiers declarator { unary-expression assignment-operator postfix-expression   curr[30]: ++  next[35]: *   declaration-specifiers declarator { unary-expression assignment-operator postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator unary-expression  declaration-specifiers declarator { unary-expression assignment-operator cast-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression   curr[35]: *  next[75]: a    curr[75]: a  next[38]: +   declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * primary-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * unary-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression * cast-expression  declaration-specifiers declarator { unary-expression assignment-operator multiplicative-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression   curr[38]: +  next[75]: b    curr[75]: b  next[38]: +   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression   curr[38]: +  next[75]: c    curr[75]: c  next[35]: *   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression   curr[35]: *  next[75]: a    curr[75]: a  next[35]: *   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression   curr[35]: *  next[30]: ++    curr[30]: ++  next[75]: b    curr[75]: b  next[36]: /   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * ++ primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * ++ postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * ++ unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression * cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression   curr[36]: /  next[76]: 4    curr[76]: 4  next[74]: ;   declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / primary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / postfix-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / unary-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression / cast-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression + multiplicative-expression  declaration-specifiers declarator { unary-expression assignment-operator additive-expression  declaration-specifiers declarator { unary-expression assignment-operator shift-expression  declaration-specifiers declarator { unary-expression assignment-operator relational-expression  declaration-specifiers declarator { unary-expression assignment-operator equality-expression  declaration-specifiers declarator { unary-expression assignment-operator AND-expression  declaration-specifiers declarator { unary-expression assignment-operator exclusive-OR-expression  declaration-specifiers declarator { unary-expression assignment-operator inclusive-OR-expression  declaration-specifiers declarator { unary-expression assignment-operator logical-AND-expression  declaration-specifiers declarator { unary-expression assignment-operator logical-OR-expression  declaration-specifiers declarator { unary-expression assignment-operator conditional-expression  declaration-specifiers declarator { unary-expression assignment-operator assignment-expression  declaration-specifiers declarator { assignment-expression  declaration-specifiers declarator { expression   curr[74]: ;  next[68]: }   declaration-specifiers declarator { expression-statement  declaration-specifiers declarator { statement  declaration-specifiers declarator { block-item  declaration-specifiers declarator { block-item-list   curr[68]: }  next[0]: NULL   declaration-specifiers declarator compound-statement  function-definition  function-definition-list  translation-unit