G ++ VS英特尔/铛参数传递顺序? [英] g++ vs intel/clang argument passing order?
问题描述
考虑以下code( LWS ):
的#include<&iostream的GT;
#包括LT&;&计时GT;内嵌无效测试(
常量的std ::时辰:: high_resolution_clock :: time_point&安培;第一,
常量的std ::时辰:: high_resolution_clock :: time_point&安培;第二)
{
性病::法院LT&;< first.time_since_epoch()计数()LT;<的std :: ENDL;
性病::法院LT&;< second.time_since_epoch()计数()LT;<的std :: ENDL;
}INT主(INT ARGC,CHAR *的argv [])
{
试验(性病::计时:: high_resolution_clock ::现在()
的std ::时辰:: high_resolution_clock ::现在());
返回0;
}
您已经跑了好几次因为有时,没有明显的区别。但是,当出现第一
和第二
,结果是下克以下++评估的时间之间的明显差异
1363376239363175
1363376239363174
和下英特尔和铛以下内容:
1363376267971435
1363376267971436
这意味着,在G ++中,第二
参数先进行计算,并根据英特尔和铿锵的第一
参数首先计算。
哪一个根据C ++ 11的标准是真的吗?
哪一个根据C ++ 11的标准是真的吗?
块引用>两者都是允许的。引用标准(§8.3.6):
函数参数评估的顺序是unspeci网络版。
块引用>Consider the following code (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; }
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
andsecond
, the result is the following under g++ :1363376239363175 1363376239363174
and the following under intel and clang :
1363376267971435 1363376267971436
It means that under g++, the
second
argument is evaluated first, and under intel and clang thefirst
argument is evaluated first.Which one is true according to the C++11 standard?
解决方案Which one is true according to the C++11 standard ?
Both are permissible. To quote the standard (§8.3.6):
The order of evaluation of function arguments is unspecified.
这篇关于G ++ VS英特尔/铛参数传递顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!