c中无符号整数的类型是什么?

时间:2014-03-06 13:59:30

标签: c++ c double unsigned unsigned-long-long-int

uint8可以表示为ubyte,uint16可以表示为uword,uint32可以表示为ulong,uint64可以表示为?

我正在搜索无符号整数如何在c中表示为数据类型,但我对如何呈现uint64感到困惑? 可以在c ??中使用uint64作为udouble吗?请有人指导我? 它会支持??

上述所有内容的格式说明符是什么?

我只是添加这一行,因为它要求正文不符合要求并告诉添加一些内容。所以我加了这个。

2 个答案:

答案 0 :(得分:3)

所有这些类型uint8,uint16,uint32,uint64都不是标准的基本类型,它们是typedef名称或实现定义类型

对于uint64,它可以定义为例如

typedef unsigned long long uint64;

考虑到整数类型的大小是实现定义的。所以可能在上面的定义中使用unsigned long就足够了,因为在某个平台上sizeof( unsigned long)可以等于8个字节。

如果您想使用不依赖于已使用平台的标准整数类型,那么您应该包含标题<cstdint>

在其他定义的类型中有以下无符号类型定义

typedef unsigned integer type uint8_t; // optional
typedef unsigned integer type uint16_t; // optional
typedef unsigned integer type uint32_t; // optional
typedef unsigned integer type uint64_t; // optional

typedef unsigned integer type uint_fast8_t;
typedef unsigned integer type uint_fast16_t;
typedef unsigned integer type uint_fast32_t;
typedef unsigned integer type uint_fast64_t;

typedef unsigned integer type uint_least8_t;
typedef unsigned integer type uint_least16_t;
typedef unsigned integer type uint_least32_t;
typedef unsigned integer type uint_least64_t;

答案 1 :(得分:2)

#include <stdint.h>

获取全局命名空间中定义的所有类型。

#include <cstdint>

在命名空间std中定义它。

关于我的实施,即stdint.h我可以找到:

#if __WORDSIZE == 64
typedef unsigned long int   uint64_t;
#else
__extension__
typedef unsigned long long int  uint64_t;
#endif

uint32_t

#ifndef __uint32_t_defined
typedef unsigned int        uint32_t;
# define __uint32_t_defined
#endif