c++ - 检查是否定义了 uint64_t

标签 c++ types preprocessor-directive

uint64_t 类型不能保证在 32 位平台上定义,并且代码如下

int main() {
  uint64_t i = 0;
}

可能会导致不完整类型的编译错误。

是否有预处理器指令来检查 uint64_t 是否存在?还有其他方法可以检查类型是否已定义吗?

最佳答案

我认为合理的方法是检查关联的宏是否UINT64_MAX已定义,例如

#include <cstdint> /* don't forget to include */

...

#ifdef UINT64_MAX
    ...
#endif

据我所知,您无法直接检查是否定义了某种类型的同义词。根据 C99,7.18.2 Limits of specified-width integer types(没有 C++ 标准的拷贝来确认,强调我的):

The following object-like macros specify the minimum and maximum limits of the types declared in <stdint.h>. Each macro name corresponds to a similar type name in 7.18.1.

关于c++ - 检查是否定义了 uint64_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24712091/

相关文章:

c++ - 从整数 vector 返回一个无符号长整数 C++

c++ - 堆分配的对象会在堆栈上分配它们的成员吗?

c++ - 如何将 char 数组转换为 float 数组?

c# - 创建可用作函数/方法的类型

c - 确定 byte 和 vec3_t 是否类型定义

C 预处理器测试多个宏的定义

c++ - 模板参数本身可以模板化吗?

c++ - 警告 : right-hand operand of comma has no effect gcc 4. 4.7

java - 根据继承类型重新初始化变量

c - 制作既是 C 标识符又是字符串的东西?