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

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

修改为

 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 *的更多相关文章

  1. char str[]和char *str的区别

    1.http://blog.csdn.net/szchtx/article/details/10396149 char ss[]="C++";  ss[0]='c';        ...

  2. C float与char数组 互转

    //转换float数据到字节数组 unsigned char i; float floatVariable; unsigned ]; (unsigned char) *pdata = ((unsign ...

  3. char*和char []

    1.char *s1 = "ssss"; 2.char s2[] = "bbbb"; 对于第一种,我是无法理解,无法想象字符串赋值给一个char类型的指针,查了 ...

  4. (void*)0 的理解

    例如: #define NULL ((void *)0) 用来定义无效的指针 (void *)0 就是将0强制转化为(void *)类型的指针 char *ch = (void *)0;//ch指向地 ...

  5. Pointer arithmetic for void pointer in C

    http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c When a pointer t ...

  6. 函数返回char* 的解决方案

    在C语言中,自动变量在堆栈中分配内存.当包含自动变量的函数或代码块退出时,它们所占用的内存便被回收,它们的内容肯定会被下一个所调用的函数覆盖.这一切取决于堆栈中先前的自动变量位于何处,活动函数声明了什 ...

  7. 【转】char *str 和 char str[]的区别

    char str[] = "abcd";定义了一个局部字符数组,返回它的地址肯定是一个已经释放了的空间的地址. 此函数返回的是内部一个局部字符数组str的地址,且函数调用完毕后 此 ...

  8. (转) int argc, char* argv[] 的用法

    int main(int argc, char* argv[]) 這兩個參數的作用是什麼呢?argc 是指命令行輸入參數的個數,argv存儲了所有的命令行參數.假如你的程式是hello.exe,如果在 ...

  9. char str[] 与 char *str的区别详细解析

    char* get_str(void) { char str[] = {"abcd"}; return str; } char str[] = {"abcd"} ...

随机推荐

  1. python抓取网页图片

    本人比较喜欢海贼王漫画,所以特意选择了网站http://www.mmonly.cc/ktmh/hzw/list_34_2.html来抓取海贼王的图片. 因为是刚刚学习python,代码写的不好,不要喷 ...

  2. 【记录】在MAC上安装caffe

    ---恢复内容开始--- 最近尝试在MAC(OS X 10.11 El Capitan)上安装Caffe 以及Python接口遇到了一些问题但是官方安装教程上并没有提出这些问题的解决办法搜索了很久(主 ...

  3. 一个jpa动态模糊查询的实现

    最近一直在是用spring data jpa,使用起来确实方便,如果是单表的操作基本上通过方法名都可以实现,下面是一个 Specification 实现动态模糊查询的例子这个查询是通过JpaSpeci ...

  4. Using Swift with Cocoa and Objective-C(Swift 2.0版):开始--基础设置-备

    这是一个正在研发的API或技术的概要文件,苹果公司提供这些信息主要是为了帮助你通过苹果产品使用这些技术或者编程接口而做好计划,该信息有可能会在未来发生改变,本文当中提到的软件应该以最终发布的操作系统测 ...

  5. 如何使用Instruments诊断App(Swift版):起步-b

    无论你写过许多iOS应用,还是刚刚开始你的第一个应用,毫无疑问,你都会想出一些新点子,或者想去弄明白你该怎么做,来让你的app变得更好. 除去添加新特性来优化你的应用,有一件事是所有好的开发者都回去做 ...

  6. 减少JAVA GC

    减少GC开销的措施:程序的运行会直接影响系统环境的变化,从而影响GC的触发.若不针对GC的特点进行设计和编码,就会出现内存驻留等一系列负面影响.为了避免这些影响,基本的原则就是尽可能地减少垃圾和减少G ...

  7. ecilipse Javadoc文档注释

    — 标签 @param @param 空格后面跟上形参(不是数据类型)空格后跟着对该参数的描述. 在描述中第一个名字为该变量的数据类型 对于参数的描述是一个句子,最好不要首字母大写, 如果出现了句号这 ...

  8. 【java】基于Tomcat的WebSocket转帖 + 自己理解

    网址:http://redstarofsleep.iteye.com/blog/1488639 原帖时间是2012-5-8,自己书写时间是2013年6月21日10:39:06 Java代码 packa ...

  9. 【HDOJ】1547 Bubble Shooter

    两次BFS,一次扫描关联点.一次扫描可能掉落的情况(即再次扫描所有非爆炸的联通点).余下未被扫描的点均爆炸. #include <cstdio> #include <cstring& ...

  10. 自己的缺省(sheng)源

    write无力吐槽了 #include <cstdio> #include <iostream> #include <algorithm> #include < ...