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"} ...
随机推荐
- 让 zend studio 识别 Phalcon语法并且进行语法提示
让 zend studio 识别 Phalcon语法并且进行语法提示 https://github.com/phalcon/phalcon-devtools/tree/master/ide 下载解压 ...
- php 面向对象编程实例 __construct 和 __destruct 区别
大多数类都有一种称为构造函数的特殊方法.当创建一个对象时,它将自动调用构造函数,也就是使用new这个关键字来实例化对象的时候自动调用构造方 法.构 造函数的声明与其它操作的声明一样,只是其名称必须是_ ...
- elasticsearch常用的插件
deb 安装/usr/share/elasticsearch/ https://github.com/hangxin1940/elasticsearch-cn-out-of-box 包可以参考 ...
- iOS项目管理:目录结构和开发流程
iOS项目管理:目录结构和开发流程 最近正在做一个大版本的更新,现在在重构中.... 发现很多人在一个项目的开始不知道开发流程是什么,也不是非常清晰的知道一个项目该有目录结构.如果项目小或者是 ...
- Solr4.8.0源码分析(11)之Lucene的索引文件(4)
Solr4.8.0源码分析(11)之Lucene的索引文件(4) 1. .dvd和.dvm文件 .dvm是存放了DocValue域的元数据,比如DocValue偏移量. .dvd则存放了DocValu ...
- angular2 学习笔记 ( Http 请求)
refer : https://angular.cn/docs/ts/latest/guide/server-communication.html https://xgrommx.github.io/ ...
- 14.4.5 System Tablespace 系统表空间
14.4.5 System Tablespace 系统表空间 InnoDB 系统表空间包含InnoDB 数据目录(元数据 用于InnoDB相关对象)和是存储区域用于doublewrite buffer ...
- Windows 10 代理上网用户的正确使用姿势
1.找不到IE,如何使用IE来配置局域网代理 打开Edge浏览器,点击选项,找到“使用Internet Explorer打开” 接下来可以使用熟练的姿势设置IE局域网代理上网了 2.Windows ...
- Linux操作系统以及各大发行版介绍——Linux operating system and major distribution is introduced
什么是Linux? 也许很多人会不屑的说,Linux不就是个操作系统么.错!Linux不是一个操作系统,严格来讲,Linux只是一个操作系统中的内核.内核是什么?内核建立了计算机软件与硬件之间通讯的平 ...
- java在windows下加载dll
java在类中加载动态链接库文件. 类文件中: static { System.loadLibrary("dll文件"); } dll文件在工程的包路径下.例如:pro/bin/h ...