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"} ...
随机推荐
- php错误级别设置
在php.ini中可以设置服务器对错误的报警级别.在默认情况下,php将报告除了通知之外的所有错误. 错误报告级别是通过一些预定义的常量来设置的, 语法 int error_reporting ( [ ...
- <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalabl ...
- asp.net(C#)写SQL语句技巧
/*添加SQL*/string fields = "";string values = "";fields += "xm"; values ...
- 转:PHP 使用ZipArchive压缩文件并下载
原文来自于:http://courages.us/archives/176 网站上需要提供一些打印数据给用户下载,这些文件每次都需要重新生成,因为随时都会有新的数据产生.网络上关于PHP的压缩功能实现 ...
- [转载] $\mathrm{Jordan}$标准型的介绍
本文转载自陈洪葛的博客$,$ 而实际上来自xida博客朝花夕拾$,$ 可惜该博客已经失效 $\mathrm{Jordan}$ 标准形定理是线性代数中的基本定理$,$ 专门为它写一篇长文好像有点多余$: ...
- Keil C51中变量和函数的绝对地址定位问题
1.变量绝对地址定位 1) 在定义变量时使用 _at_ 关键字加上地址就可. unsigned char idata myvar _at_ 0x40; 把变量 myvar 定义在 idata 的 0 ...
- 【HDOJ】4857 逃生
很容易想到优先队列+拓扑排序.关键点是有限制条件者有限,无限制条件者在最后,条件相同者按序输出.因此采用逆序. #include <iostream> #include <queue ...
- COJ 2003 选根 (树的重心)
我们可以用树形DP在线性复杂度内搞定重心. #include<iostream> #include<cstdio> #include<cmath> #include ...
- HttpURLConnection和HttpClient
HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.在 JDK 的 java.net 包中已经提供了访问 ...
- jstat(JVM Statistics Monitoring Tool)
功能 用于监视虚拟机各种运行状态信息的命令行工具.它可以显示本地或远程虚拟机进程中的类装载.内存.垃圾收集.JIT编译等运行数据,在没有GUI图形界面,只提供了纯文本控制台环境的服务器上,它将是运 ...