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里的拷贝=====》很容易错误的

    不能直接用 = 复制: import copy a = [1, 2, 3, 4, ['a', 'b']] #原始对象 b = a #赋值,传对象的引用 c = copy.copy(a) #对象拷贝,浅 ...

  2. [Apio2014]回文串

    http://www.lydsy.com:808/JudgeOnline/problem.php?id=3676 这是一道回文树裸题,具体如何建图见http://blog.csdn.net/u0133 ...

  3. jquery-te 轻量级的编辑器

  4. C获取本地时间的localtime函数

    最近有朋友问如下问题: #include <stdio.h>#include <stdlib.h>#include <iconv.h>#include <ti ...

  5. 感兴趣的Linux发行版

    1. Ubuntu,包括KUbuntu,XUbuntu,Kyrin等等 2. BluestarLinux - 基于Arch Linux,感觉很美 http://sourceforge.net/proj ...

  6. 调用系统API还是很高效的,不必担心性能

    代码如下: void MainWindow::on_pushButton_2_clicked() { QTime total; total.start(); ; ; i<=*; i++) { Q ...

  7. 使用GetLogicalProcessorInformation获取逻辑处理器的详细信息(NUMA节点数、物理CPU数、CPU核心数、逻辑CPU数、各级Cache)

    不过必须XP SP3以上才行.所有API大全: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363804(v=vs.85).a ...

  8. 14.2 InnoDB and the ACID Model

    14.2 InnoDB and the ACID Model ACID 模型是一组数据库设计原则,强调可靠性方面对于商业数据和关键人物. MySQL 包含组件比如InnoDB存储引擎坚持ACID 模型 ...

  9. BZOJ1524: [POI2006]Pal

    1524: [POI2006]Pal Time Limit: 5 Sec  Memory Limit: 357 MBSubmit: 308  Solved: 101[Submit][Status] D ...

  10. fmt命令

    简单的格式化文本 fmt [option] [file-list] fmt通过将所有非空白行的长度设置为几乎相同,来进行简单的文本格式化 参数 fmt从file-list中读取文件,并将其内容的格式化 ...