我正在考虑以下C++程序:
#include <iostream>
#include <limits>
int main(int argc, char **argv) {
unsigned int sum = 0;
for (unsigned int i = 1; i < std::numeric_limits<unsigned int>::max(); ++i) {
double f = static_cast<double>(i);
unsigned int t = static_cast<unsigned int>(f);
sum += (t % 2);
}
std::cout << sum << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用gcc/g ++编译器,g ++ -v给出了gcc版本4.7.2 20130108 [gcc-4_7-branch revision 195012](SUSE Linux).我正在运行openSUSE 12.3(x86_64)并拥有Intel(R)Core(TM)i7-3520M CPU.
运行
g++ -O3 test.C -o test_64_opt
g++ -O0 test.C -o test_64_no_opt
g++ -m32 -O3 test.C -o test_32_opt …Run Code Online (Sandbox Code Playgroud)