void*指针的一些冷知识
2015-08-27 04:40
260 查看
Pointer (computer programming)
Pointer arithmetic cannot be performed on void pointers because the void type has no size, and thus the pointed address can not be added to, although gcc and other compilers will perform byte arithmetic on void* as a non-standard extension, treating it as if it were char *.
Pointer Arith
In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.
so...sizeof(void *) = sizeof(char *) = 4.
by the way, sizeof(char) = 1.
如果一个变量point的类型是void*,他在point++ ,point = point + 1 等操作的时候,是往下数1个字节。因为void*会被默认当作char*
Pointer arithmetic cannot be performed on void pointers because the void type has no size, and thus the pointed address can not be added to, although gcc and other compilers will perform byte arithmetic on void* as a non-standard extension, treating it as if it were char *.
Pointer Arith
In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.
so...sizeof(void *) = sizeof(char *) = 4.
by the way, sizeof(char) = 1.
如果一个变量point的类型是void*,他在point++ ,point = point + 1 等操作的时候,是往下数1个字节。因为void*会被默认当作char*
相关文章推荐
- 《计算机网络基础》考点笔记
- Leetcode: String to Integer (atoi)
- 【小熊刷题】Single Number II
- NoClassDefFoundError的一个解决方法
- [LeetCode#84]Largest Rectangle in Histogram
- hdu KM匹配题集
- hdu 差分约束题集
- iOS开发学习之UITableView
- leetcode #8 atoi
- 淘宝搜索技术代码你知多少
- hdu 2sat题集
- Leetcode: Min Stack
- Leetcode: Min Stack
- Javascript获取select下拉框选中的的值
- 直接读写设备文件
- Leetcode: Majority Element
- hdoj4539郑厂长系列故事——排兵布阵【状压dp】
- Centos7安装及使用webbench进行并发测试
- Linux用户和组管理
- C++ Primer : 第十二章 : 动态内存之allocator类