我想在我的 C++ 代码中使用 64 位整数。我知道我可以 #include <cstdint>
然后声明一个uint64_t
或使用 unsigned long long
(或签名版本的等价物)。
但是,似乎直到 C++11
才添加对此的支持并且我希望我的代码与不具有完整 C++11 支持的编译器兼容。
在 C++ 中支持 64 位整数的良好可移植方式是什么?
最佳答案
uint64_t
是:
Optional: These typedefs are not defined if no types with such characteristics exist.
正如您在 ref 中所读到的那样.
来自 Should I use long long or int64_t for portable code? :
The types
long long
andunsigned long long
are standard C and standard C++ types each with at least 64 bits. All compilers I'm aware of provide these types, except possibly when in a-pedantic
mode but in this caseint64_t
oruint64_t
won't be available with pre-C++ 2011 compilers, either. "
g++/clang 从什么时候开始支持long long
/int64_t
?
Since GCC 4.3 (aka March 5, 2008).
正如 David Álvarez 提到的。
关于c++ - 64 位整数和旧的 C++ 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574682/