This code gives different outputs in XCode and in Visual Studio:
#include <iostream>
using namespace std;
int f() {
cout << 'A';
return 1;
}
int main() {
cout << '.' << f();
return 0;
}
In Visual Studio it outputs
A.1
In XCode it outputs
.A1
Obviously I'd expect both compilers to output the same thing.. Is it to be expected to not do that? Is it a known thing or is there anything I could do about this?
MSVC compiles the code differently than GCC apparently.
Inspecting the assembly code through Godbolt (using x86-64 gcc 13.2 and x64 msvc v19.38) shows that MSVC produces the following assembly for the
mainfunction:... while GCC produces this:
In the MSVC output,
f()is called before the firstoperator<<, while GCC callsf()after calling the firstoperator<<onstd::cout.The reason for this is that in C++, the order of evaluation is unspecified: