c++ - 64 位整数和旧的 C++ 编译器

标签 c++ types portability int64 long-long

我想在我的 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 and unsigned 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 case int64_t or uint64_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/

相关文章:

C++ 整数常量 + 选择运算符 = 问题!

c++ - 重写一个类以使其更通用以实现可移植性

c++ - 抽象类类型指针编译成功?

c++ - POCO::PostgreSQL:如何将std::vector支持添加到 `Binder::bind`?

c++ - 可用空间大小信息

generics - 在 Swift 中获取泛型类型的名称(字符串)

java - 如何在此对象中应用多态性

delphi - 如何重载整数的简单 Delphi 函数?

database - 我应该克隆或反规范化我的数据库以供可移植使用吗?

c++ - 如何在编译时初始化静态二维数组