I got code like this:
#include <iostream>
int f1() {
std::cout << 1 << std::endl;
return 1;
}
int f2() {
std::cout << 2 << std::endl;
return 2;
}
class Bar {
public:
Bar(int i, int j) {}
};
int main() {
Bar bar(f1(), f2());
}
When the code compiled using gcc 7.4.0, the out put is 2 1
, while when using clang 6.0, the out put is 1 2
.
So I got questions:
Is calling order of paramters an undefined behavior? If so, can I force compiler to call in order if f1()
and f2()
in order(in some cases the order of f1()
and f2()
matters)? And is this a good practice(compare with call them orderly and pass the result to the function)?