在osx/win7/linux上不同的c++调用转换
Different c++ calling conversion on osx/win7/linux
我遇到一个奇怪的问题。c++的调用约定似乎不同于win/linux和macosx
以下代码的行为在MacOSX/linux/Win7 (64bit)上不同
MacOSX: Apple LLVM version 6.1.0 (clang-602.0.53)(基于LLVM 3.6.0svn)
Linux: gcc version 4.8.4Win7: VS2015
在Win7/Linux:
this is method1
this is method2
this is method3
this is method4
this is method5
this is method6
this is method7
this is method8
this is method9
在MacOsx this is method9
this is method8
this is method7
this is method6
this is method5
this is method4
this is method3
this is method2
this is method1
代码如下:
#include <iostream>
int method1(){
std::cout << "this is method1" << std::endl ;
return 1;
}
int method2(){
std::cout << "this is method2" << std::endl;
return 1;
}
int method3(){
std::cout << "this is method3" << std::endl;
return 1;
}
int method4(){
std::cout << "this is method4" << std::endl;
return 1;
}
int method5(){
std::cout << "this is method5" << std::endl;
return 1;
}
int method6(){
std::cout << "this is method6" << std::endl;
return 1;
}
int method7(){
std::cout << "this is method7" << std::endl;
return 1;
}
int method8(){
std::cout << "this is method8" << std::endl;
return 1;
}
int method9(){
std::cout << "this is method9" << std::endl;
return 1;
}
void caller(int, int,int, int,int, int,int, int,int){
}
int main(){
caller(method1(), method2(),method3(), method4(),method5(), method6(),method7(), method8(),method9());
return 0;
}
虽然调用约定确实因平台而异,但这不是调用约定不同的结果,而是求值顺序,这是实现定义的。
这意味着顺序可能不仅因操作系统而异,而且因编译器而异(理论上甚至在不同的编译器版本之间)。因此,您的代码不应该依赖于特定的求值顺序。
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 函数调用中参数的顺序重要吗
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在c++类上调用void函数
- 为什么 std::unique 不调用 std::sort?
- 调用专用模板时出错"no matching function for call to [...]"
- 选择要调用的构造函数
- C++为什么尽管我调用了void函数,它却不起作用
- 构造函数正在调用一个使用当前类类型的函数
- 变量没有改变?通过向量的函数调用
- 没有为自己的结构调用列表推回方法
- 调用'begin(int [n])'没有匹配函数
- 什么时候调用析构函数
- 如何用参数值调用函数(仅在运行时已知)
- std::cout.imbue()多重调用
- 函数何时会在c++中包含stack_Unwind_Resume调用