码迷,mamicode.com
首页 > 其他好文 > 详细

char * 和 void *

时间:2014-09-01 00:11:52      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   io   strong   ar   for   

POSIX.1 将 read函数的原型做了修改,经典的定义为

1 int read(int filedes, char *buf, unsigned nbytes);

修改为

1 ssize_t read(int filedes, void *buf, size_t nbytes);

主要从以下几个方面考虑

  • First, the second argument was changed from a char * to a void * to be consistent with ISO C: the type void * is used for generic pointers.

  • Next, the return value must be a signed integer (ssize_t) to return a positive byte count, 0 (for end of file), or 1 (for an error).
  • Finally, the third argument historically has been an unsigned integer, to allow a 16-bit implementation to read or write up to 65,534 bytes at a time. With the 1990 POSIX.1 standard, the primitive system data type ssize_t was introduced to provide the signed return value, and the unsigned size_t was used for the third argument. (Recall the SSIZE_MAX constant from Section 2.5.2.)

引自 <Advanced Programming in the UNIX® Environment: Second Edition>

中文名为<UNIX环境高级编程:第二版>

char * 和 void *

标签:des   style   blog   color   os   io   strong   ar   for   

原文地址:http://www.cnblogs.com/listened/p/3948345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!