/* We don‘t have #include_next. Define ANSI <limits.h> for standard 32-bit words. */
/* These assume 8-bit ‘char‘s, 16-bit ‘short int‘s, and 32-bit ‘int‘s and ‘long int‘s. */
1.char数据类型
char类型数据所占内存空间为8位。其中有符号字符型变量取值范围为?128~127,无符号型字符变量取值范围为0~255.其限制如下:
/* Number of bits in a ‘char‘. */
# define CHAR_BIT 8 //所占字节数
/* Minimum and maximum values a ‘signed char‘ can hold. */ //有符号字符型范围
# define SCHAR_MIN (-128)
# define SCHAR_MAX 127
/* Maximum value an ‘unsigned char‘ can hold. (Minimum is 0.) */ //无符号字符型范围
# define UCHAR_MAX 255
/* Minimum and maximum values a ‘char‘ can hold. */
# ifdef __CHAR_UNSIGNED__
# define CHAR_MIN 0
# define CHAR_MAX UCHAR_MAX
# else
# define CHAR_MIN SCHAR_MIN
# define CHAR_MAX SCHAR_MAX
# endif
2.short int数据类型
short int类型数据所占内存空间为16位。其中有符号短整型变量取值范围为?32768~32767,无符号短整型变量取值范围为0~65535.其限制如下:
/* Minimum and maximum values a ‘signed short int‘ can hold. */ // 有符号短整型范围
# define SHRT_MIN (-32768)
# define SHRT_MAX 32767
/* Maximum value an ‘unsigned short int‘ can hold. (Minimum is 0.) */
// 无符号短整型范围
# define USHRT_MAX 65535
3.int数据类型int类型数据所占内存空间为32位。其中有符号整型变量取值范围为-2147483648~2147483647,无符号型整型变量取值范围为0~4294967295U.其限制如下:
/* Minimum and maximum values a ‘signed int‘ can hold. */ //整形范围
# define INT_MIN (-INT_MAX - 1)
# define INT_MAX 2147483647
/* Maximum value an ‘unsigned int‘ can hold. (Minimum is 0.) */
//无符号整形范围# define UINT_MAX 4294967295U
4.long int数据类型
随着宏__WORDSIZE值的改变,long int数据类型的大小也会发生改变。如果__WORDSIZE的值为32,则long int和int类型一样,占有32位。在Linux GCC4.0-i386版本中,默认情况下__WORDSIZE的值为32.其定义如下:
//come from /usr/include/bits/wordsize.h
#define __WORDSIZE 32
在64位机器上,如果__WORDSIZE的值为64, long int类型数据所占内存空间为64位。其中有长整型变量取值范围为-9223372036854775808L~9223372036854775807L,无符号长整型变量取值范围为0~18446744073709551615UL.其限制如下:
/* Minimum and maximum values a ‘signed long int‘ can hold. */ //有符号长整形范围
# if __WORDSIZE == 64
# define LONG_MAX 9223372036854775807L
# else
# define LONG_MAX 2147483647L
# endif
# define LONG_MIN (-LONG_MAX - 1L)
/* Maximum value an ‘unsigned long int‘ can hold. (Minimum is 0.) *///无符号长整形范围
# if __WORDSIZE == 64
# define ULONG_MAX 18446744073709551615UL
# else
# define ULONG_MAX 4294967295UL
# endif
5.long long int数据类型
在C99中,还定义了long long int数据类型。其数据类型限制如下:
# ifdef __USE_ISOC99
/* Minimum and maximum values a ‘signed long long int‘ can hold. *///无符号长长整形范围
# define LLONG_MAX 9223372036854775807LL
# define LLONG_MIN (-LLONG_MAX - 1LL)
/* Maximum value an ‘unsigned long long int‘ can hold. (Minimum is 0.) *///有符号长长整形范围
# define ULLONG_MAX 18446744073709551615ULL
# endif /* ISO C99 */
Linux数据类型大小--->int,char,long int,long long int,布布扣,bubuko.com