try it, then you know it____________just do it , as love easily fade.

一次只有一个目标,步子迈小些,抑制一次实现所有功能的冲动。 过程如何结果就如何,行动是欢喜的,不管是兴奋还是沮丧的情绪都对结果无益。贵在持之以恒

导航

C 数据类型 长度

----数据类型长度

C99标准并不规定具体数据类型的长度大小。计算机具有不同位数的处理器,16,32和更高位的64位处理器,在这些不同的平台上,同一种数据类型具有不同的长度。

char,short,长度相同,分别为1和2个字节。

int 在32和64位处理器上皆为4个字节,在16位上是2个字节。

long在16和32位处理器上皆为4个字节,在64位上是8个字节。

long long 在16和32位处理器上皆为8个字节.

指针类型的位数与各个处理器的位数相同,分别位16,32,64位。

为了便于平台的移植,需要确保数据类型长度的一致,引用stdint.h头文件,利用宏定义固定数据类型的长度。

typedef signed char       int8_t
typedef short int         int16_t;
typedef int               int32_t;
# if __WORDSIZE == 64
typedef long int          int64_t;
# else
__extension__
typedef long long int     int64_t;

//unsigned type is the same and omitted here

----uintptr_t,intptr_t 

指针类型的长度与处理器的位数相同,需要对指针进行运算时,利用intptr_t类型,引用stddef.h头文件

#if __WORDSIZE == 64
typedef long int                intptr_t;
#else
typedef int                     intptr_t;
#endif
//unsigned type is the same and omitted here

----编程中要尽量使用sizeof来计算数据类型的大小

----size_t, ssize_t (in stddef.h)

Are the types size_t and uintptr_t equivalent?(http://www.viva64.com/en/k/0024/)

二者数值上相同,同处理器步长。

--in practice you can consider them equivalent and use them as you like.   

Usually size_t is used to emphasize we are dealing with a object containing same size,number of elements or iterations;   The type uintptr_t is good for pointers.

 

posted on 2015-03-06 17:08  吾一  阅读(2468)  评论(0编辑  收藏  举报