有什么方法可以设置 8 字节 (x64) 的 C++ 长类型大小?

Is there any way to set C++ long type size with 8 bytes (x64)?

GCC 使用 sizeof(long)=8 编译程序,Visual Studio 有 sizeof(long)=4。如何在 Windows x64 上将 sizeof(long) 设置为 8 字节?

longisn't specified to be an exact number of bytes的实际大小,只是它必须能够表示的数值范围。但是你可以使用固定宽度的整数

std::int64_t

<cstdint>

中提供了此类型以及其他固定宽度整数类型

这是一个常见的迁移问题:https://msdn.microsoft.com/en-us/library/3b2e7499.aspx。如前所述,规范没有具体说明 long 的大小,done 平台将是 4 和 sone 8。