char * 和 void *
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 *的更多相关文章
- char str[]和char *str的区别
1.http://blog.csdn.net/szchtx/article/details/10396149 char ss[]="C++"; ss[0]='c'; ...
- C float与char数组 互转
//转换float数据到字节数组 unsigned char i; float floatVariable; unsigned ]; (unsigned char) *pdata = ((unsign ...
- char*和char []
1.char *s1 = "ssss"; 2.char s2[] = "bbbb"; 对于第一种,我是无法理解,无法想象字符串赋值给一个char类型的指针,查了 ...
- (void*)0 的理解
例如: #define NULL ((void *)0) 用来定义无效的指针 (void *)0 就是将0强制转化为(void *)类型的指针 char *ch = (void *)0;//ch指向地 ...
- Pointer arithmetic for void pointer in C
http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c When a pointer t ...
- 函数返回char* 的解决方案
在C语言中,自动变量在堆栈中分配内存.当包含自动变量的函数或代码块退出时,它们所占用的内存便被回收,它们的内容肯定会被下一个所调用的函数覆盖.这一切取决于堆栈中先前的自动变量位于何处,活动函数声明了什 ...
- 【转】char *str 和 char str[]的区别
char str[] = "abcd";定义了一个局部字符数组,返回它的地址肯定是一个已经释放了的空间的地址. 此函数返回的是内部一个局部字符数组str的地址,且函数调用完毕后 此 ...
- (转) int argc, char* argv[] 的用法
int main(int argc, char* argv[]) 這兩個參數的作用是什麼呢?argc 是指命令行輸入參數的個數,argv存儲了所有的命令行參數.假如你的程式是hello.exe,如果在 ...
- char str[] 与 char *str的区别详细解析
char* get_str(void) { char str[] = {"abcd"}; return str; } char str[] = {"abcd"} ...
随机推荐
- Delphi-CompareStr 函数
函数名称 CompareStr 所在单元 System.SysUtils 函数原型 function CompareStr(const S1, S2: string): Integer; 函数功能 比 ...
- HTML&CSS基础学习笔记1.31-像素和相对长度
像素和相对长度 之前的笔记中,我们提到过用属性width.height来设置图片的尺寸,它们的单元都是”px(像素)”.长度单位总结一下,目前比较常用到px(像素).em.% 百分比,要注意其实这三种 ...
- lua curl动态链接库编译安装
关于lua curl的资料网上并不是很多.找来找去就那么几个,所以我绝得很有必要把我的经验记下来,以防下次忘记 ...
- 查看 yum 安装软件包的路径
yum:列出已安装的安装包 [root@localhost ~]# yum list | grep mysql akonadi-mysql.x86_64 1.9.2-4.el7 base apr-ut ...
- Linux前传——今天的学习
感觉每天早上搞一个C语言的趣味题,很不错,算是比较实际的事情了.而且,好多都不会,主要是算法,也有很多语法不知道,这样补强很有用.嵌入式方面的课题进展有条不紊,感觉相关寄存器和I/O的使用必须通过大量 ...
- Common Subsequence
#include<cstdio> #include<iostream> #include<cmath> #include<string> #includ ...
- windows下和linux下 Redis 安装
Redis 是一个高性能的key-value数据库, 使用内存作为主存储,数据访问速度非常快,当然它也提供了两种机制支持数据持久化存储.比较遗憾的是,Redis项目不直接支持Windows,Windo ...
- 【HDOJ】2492 Ping pong
线段树+离散化. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 2000 ...
- 【转】android去掉EditView的默认焦点问题
原文网址:http://www.111cn.net/sj/android/54680.htm 做一个输入框时发现android中EditView的默认焦点了,这种问题如果是在输入框还好,但在搜索页面或 ...
- Gas Station——LeetCode
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...