g++ 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++下的结果如下:
You have to run it several times because sometimes, there is no visible difference. But when there is a visible difference between the time of evaluation of first
and second
, the result is the following under g++ :
1363376239363175
1363376239363174
以及 intel 和 clang 下的以下内容:
and the following under intel and clang :
1363376267971435
1363376267971436
这意味着在 g++ 下,首先评估 second
参数,而在 intel 和 clang 下,首先评估 first
参数.
It means that under g++, the second
argument is evaluated first, and under intel and clang the first
argument is evaluated first.
根据 C++11 标准,哪个是正确的?
Which one is true according to the C++11 standard?
推荐答案
根据 C++11 标准,哪个是正确的?
Which one is true according to the C++11 standard ?
两者都是允许的.引用标准(第 8.3.6 节):
Both are permissible. To quote the standard (§8.3.6):
函数参数的计算顺序未指定.
The order of evaluation of function arguments is unspecified.
这篇关于g++ vs intel/clang 参数传递顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!