linux初级入门-经典函数记录
2014-05-03 13:11
447 查看
offsetof
offsetof (type,member)
Return member offset
This macro with functional form returns the offset value in bytes of member member in the data structure or union type
type.
The value returned is an unsigned integral value of type
size_t with the number of bytes between the specified member and the beginning of its structure.
Parameters
typeA type in which member is a valid member designator.C
C++98
C++11
type shall be a structure or union type.
type shall be a POD class (including unions).
type shall be a standard-layout class (including unions).
memberA member of type.
Return value
A value of type size_t with the offset value ofmember in type.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /* offsetof example */ #include <stdio.h> /* printf */ #include <stddef.h> /* offsetof */ struct foo { char a; char b[10]; char c; }; int main () { printf ("offsetof(struct foo,a) is %d\n",(int)offsetof(struct foo,a)); printf ("offsetof(struct foo,b) is %d\n",(int)offsetof(struct foo,b)); printf ("offsetof(struct foo,c) is %d\n",(int)offsetof(struct foo,c)); return 0; } |
offsetof(struct foo,a) is 0 offsetof(struct foo,b) is 1 offsetof(struct foo,c) is 11 |
相关文章推荐
- Linux 入门记录:一、命令行 Bash 的基本操作
- RedHat_Linux环境下防火墙配置初级入门
- 转载只为记录经典之<使用linux中的sed编辑器>
- javascript入门经典学习四(对象,流程控制,函数)
- Linux 入门记录:八、Linux 文件系统
- Linux网络编程入门必备函数说明
- arm嵌入式linux qt入门问答,很经典!!
- Oracle编程入门经典 第11章 过程、函数和程序包
- c#入门经典入门经典-调试函数的运用
- 转载只为记录经典之<linux 驱动是什么>
- Linux 系统函数记录 open
- 真实记录我入门学习Linux系统的经历
- arm嵌入式linux qt入门问答,很经典!!
- Linux之GCC经典入门教程
- Linux 入门记录:十九、Linux 包管理工具 RPM
- RedHat_Linux环境下防火墙配置初级入门
- (转)经典:Linux菜鸟入门级命令大全
- 算法竞赛入门经典: 第四章 函数与递归 4.2组合数
- Linux驱动--函数,宏,结构体理解记录
- arm嵌入式linux qt入门问答,很经典!!