简单的C数据类型

可能重复:
int8_t,int_least8_t和int_fast8_t的区别?

我很困惑。 我想……(如果我错了,请纠正我)

u_int8_t = unsigned short ? u_int16_t = unsigned int ? u_int32_t = unsigned long ? u_int64_t = unsigned long long ? int8_t = short ? int16_t = int ? int32_t = long ? int64_t = long long ? 

然后int_fast8_t是什么意思? int_fastN_tint_least8_t

这些都在C99标准中规定(第7.18节)。

[u]intN_t类型是generics类型(在ISO C标准中),其中N表示位宽(8,16等)。 8位不一定是shortchar因为short / ints / longs / etc被定义为具有最小范围(不是位宽),并且可能不是2的补码。

这些较新的类型两个补码,不管更常见类型的编码,可以是补码或符号/幅度(参见C中负数的表示?以及为什么SCHAR_MIN在C99中定义为-127? )。

fastleast正是它们的声音,快速最小宽度类型和至少给定宽度的类型。

该标准还详细说明了哪种类型是必需的,哪些是可选的。

我写的int是16位:

 u_int8_t = unsigned char u_int16_t = unsigned int u_int32_t = unsigned long int u_int64_t = unsigned long long int int8_t = char int16_t = int int32_t = long int int64_t = long long int 

问:“那么int_fast8_t是什么意思?int_fastN_t?int_least8_t?”

正如dan04在答案中所述 :

假设您有一个36位系统的C编译器, char = 9位, short = 18位, int = 36位, long = 72位。 然后

  • int8_t 不存在 ,因为没有办法满足恰好有 8个值位而没有填充的约束。
  • int_least8_tchar的typedef。 不是shortint ,因为标准要求最小类型至少8位。
  • int_fast8_t可以是任何东西。 如果“原生”大小被认为是“快”的话,它可能是int的typedef。

如果您使用Linux大多数都在/usr/include/linux/coda.h中定义。 例如

 #ifndef __BIT_TYPES_DEFINED__ #define __BIT_TYPES_DEFINED__ typedef signed char int8_t; typedef unsigned char u_int8_t; typedef short int16_t; typedef unsigned short u_int16_t; typedef int int32_t; typedef unsigned int u_int32_t; #endif 

 #if defined(DJGPP) || defined(__CYGWIN32__) #ifdef KERNEL typedef unsigned long u_long; typedef unsigned int u_int; typedef unsigned short u_short; typedef u_long ino_t; typedef u_long dev_t; typedef void * caddr_t; #ifdef DOS typedef unsigned __int64 u_quad_t; #else typedef unsigned long long u_quad_t; #endif