linux size t 定义,size_t 和 time_t 的定义和区别

size_t 在32和64位不同:

32:

/usr/include/asm/posix_types.h:18:typedef unsigned int     __kernel_size_t;

/usr/include/linux/types.h:39:typedef __kernel_size_t              size_t;

64:

/usr/include/asm-i386/posix_types.h:18:typedef unsigned int        __kernel_size_t;

/usr/include/asm-x86_64/posix_types.h:18:typedef unsigned long     __kernel_size_t;

/usr/include/linux/types.h:39:typedef __kernel_size_t              size_t;

time_t 在32和64位相同:

/usr/include/linux/types.h:54:typedef __kernel_time_t              time_t;

/usr/include/asm/posix_types.h:21:typedef long             __kernel_time_t;

由此看来,size_t 只有在64位下,才能放得下time_t.

转自:http://gcoder.blogbus.com/logs/49171704.html

————————————————————————————————————————

From a programming perspective, the LP64 model means we cannot assume that a pointer can be stored in an integer. We must also consider the effect of the LP64 model on existing APIs

ANSI C invented the size_t datatype, which is used, for example, as the argument to malloc (the number of bytes to allocate), and as the third argument to read and write (the number of bytes to read or write). On a 32-bit system, size_t is a 32-bit value, but on a 64-bit system, it must be a 64-bit value, to take advantage of the larger addressing model. This means a 64-bit system will probably contain a typedef of size_t to be an unsigned long.

--《 UNIX® Network Programming Volume 1, Third Edition 》

——————————————————————————————————————————————

如果在一个表示“数据类型的大小”的地方使用unsigned   int或者BYTE,别人很容易看不明白;但是如果在这里写上size_t,就比较容易明白了。cd /usr/include

grep time_t * -r

grep __time_t * -r

typedef   long   int   __time_t;     //   typedef   __time_t   time_t;   //   因此,time_t   是   long   int。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值