Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1325899
  • 博文数量: 436
  • 博客积分: 7854
  • 博客等级: 少将
  • 技术积分: 3225
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-18 16:30
文章分类

全部博文(436)

文章存档

2013年(2)

2012年(56)

2011年(70)

2010年(308)

分类:

2010-05-06 00:25:03

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。
阅读(1466) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~