首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这个是vs的不标准还是微软的特殊用意[fun(k,k++)],该怎么解决

2012-02-29 
这个是vs的不标准还是微软的特殊用意[fun(k,k++)]C/C++ code#include cstdlib#include iostreamusing

这个是vs的不标准还是微软的特殊用意[fun(k,k++)]

C/C++ code
#include <cstdlib>#include <iostream>using namespace std;int fun(int a, int b){    return a+b;}int _tmain(int argc, char *argv[]){    int k=1;    cout<<"fun(k,k++):"<<fun(k,k++)<<endl;    k = 1;    cout<<"fun(k++,k):"<<fun(k++,k)<<endl;    k = 1;    cout<<"fun(k,++k):"<<fun(k,++k)<<endl;    k = 1;    cout<<"fun(++k,k):"<<fun(++k,k)<<endl;    system("PAUSE");    return EXIT_SUCCESS;}


vs2005/vs2010的输出:
fun(k,k++):3
fun(k++,k):3
fun(k,++k):4
fun(++k,k):4
请按任意键继续. . .

dev cpp的输出:
fun(k,k++):3
fun(k++,k):2
fun(k,++k):4
fun(++k,k):3
请按任意键继续. . .

devcpp的结果跟我想的一样,考虑到了k++和++k的区别,已经参数入栈的方式
而vs的结果。。百思不得其解。。。

[解决办法]
嗯,荒芜 50分
[解决办法]
这个事根部不同的编译器决定的 编译器的入栈顺序
[解决办法]
这个标准里面没有规定,不同的编译器可以不一样的。没必要纠结则个
[解决办法]
楼主,珍惜生命,别折腾C、c++标准明确指出的求值顺序不确定问题,这在csdn都是日经贴问题了。
[解决办法]
编译器相关的,参考:
http://topic.csdn.net/u/20110826/09/601EBE9C-C2AE-4D63-A4E2-506C618BB654.html

热点排行