c++ vs intel/clang参数传递顺序
g++ vs intel/clang argument passing order?
考虑以下代码(LWS):
#include <iostream>
#include <chrono>
inline void test(
const std::chrono::high_resolution_clock::time_point& first,
const std::chrono::high_resolution_clock::time_point& second)
{
std::cout << first.time_since_epoch().count() << std::endl;
std::cout << second.time_since_epoch().count() << std::endl;
}
int main(int argc, char* argv[])
{
test(std::chrono::high_resolution_clock::now(),
std::chrono::high_resolution_clock::now());
return 0;
}
您必须多次运行它,因为有时没有明显的差异。但当first
和second
的评价时间有明显差异时,在g++下的结果如下:
1363376239363175
1363376239363174
和以下Intel和clang:
1363376267971435
1363376267971436
表示在g++下,先求second
参数,在intel和clang下,先求first
参数。
根据c++ 11标准哪个是正确的?
根据c++ 11标准,哪个是正确的?
都是允许的。引用标准(§8.3.6):
函数参数的求值顺序未指定。
我有一个稍微简单一点的例子来说明同样的问题。
bash$ cat test.cpp
#include <iostream>
using namespace std;
int x = 0;
int foo()
{
cout << "foo" << endl;
return x++;
}
int bar()
{
cout << "bar" << endl;
return x++;
}
void test_it(int a, int b)
{
cout << "a = " << a << endl
<< "b = " << b << endl;
}
int main(int argc, const char *argv[])
{
test_it(foo(),bar());
return 0;
}
bash$ clang++ test.cpp && ./a.out
foo
bar
a = 0
b = 1
bash$ g++ test.cpp && ./a.out
bar
foo
a = 1
b = 0
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 使用指向成员的指针将成员函数作为参数传递
- 如何将参数传递给正在使用模板的类
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 修改函数中的指针(将另一个指针作为参数传递)
- 如何将部分流作为参数传递
- 我正在开发服务器,ip作为参数传递不起作用
- 将成员函数指针作为参数传递给模板方法
- 如何在C++中将迭代器作为函数参数传递
- 将附加参数传递给使用 beast::bind_front_handler 调用的函数
- 如何将一个类的函数作为另一个类的另一个函数的参数传递
- 将参数传递为"const"的奇怪效果
- 如何在 c++ 中将函数作为参数传递?
- 在 C++ 中将非指定类型作为参数传递的最佳方法?
- 使用引用与指针将数组作为参数传递
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 将参数打包的参数传递到 std::queue 中,以便稍后使用不同的函数调用
- c++ vs intel/clang参数传递顺序
- 在将参数传递给类的构造函数的顺序中是否有任何协议或同意?