Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ vs intel/clang argument passing order?

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 and second, 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 the first argument is evaluated first.

Which one is true according to the C++11 standard?

like image 506
Vincent Avatar asked Mar 15 '13 19:03

Vincent


1 Answers

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.

like image 156
NPE Avatar answered Sep 24 '22 10:09

NPE