首页 > 代码库 > char * 和 void *
char * 和 void *
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 *
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。