这是目前在 Windows 10 上运行的 32 位 MFC 应用程序。使用 Visual C++ 2013 编译。
std::cout << "sizeof(long long) = " << sizeof(long long) << std::endl;
int rot{ 32 };
long long bits{ (1 << rot) };
std::cout << "bits with variable = " << bits << std::endl;
long long bits2 = (1 << 32);
std::cout << "bits2 with constant = " << bits2 << std::endl;
system("pause");
long long 的大小是 8 个字节,足以管理我的 32 位,我在想。这是调试版本的输出:
sizeof(long long) = 8
bits with variable = 1
bits2 with constant = 0
Press any key to continue . . .
这是发布版本的输出:
sizeof(long long) = 8
bits with variable = 0
bits2 with constant = 0
Press any key to continue . . .
所以,很明显,即使是 64 位数据类型,我的单个位也会被左移到遗忘状态。但是我真的很困惑,如果我将变量作为参数与常量相比,为什么调试构建会产生不同的输出?