检查是否定义了 uint64_t [英] check if uint64_t is defined

查看:62
本文介绍了检查是否定义了 uint64_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

uint64_t 类型不保证在 32 位平台上定义,代码类似

The type uint64_t is not guaranteed to be defined on 32-bit platforms, and code like

int main() {
  uint64_t i = 0;
}

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

may result in compilation errors of the type incomplete type.

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

Is there a preprocessor directive to check if uint64_t is present? Any other way for checking if the type is defined?

推荐答案

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

I think that reasonable approach is to check if associated macro UINT64_MAX is defined, e.g.

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

...

#ifdef UINT64_MAX
    ...
#endif

AFAIK 你不能直接检查是否定义了某种类型的同义词.根据 C99,7.18.2 指定宽度整数类型的限制(没有 C++ 标准的副本来确认,强调我的):

AFAIK you can't check directly if some type synonym is defined. According to C99, 7.18.2 Limits of specified-width integer types (don't have copy of C++ standard to confirm, emphasis mine):

以下类对象宏指定最小值和最大值声明的类型的限制.每个宏名称对应于 7.18.1 中类似的类型名称.

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.

这篇关于检查是否定义了 uint64_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆