当前位置:网站首页>自定义实现offsetof
自定义实现offsetof
2022-06-11 21:36:00 【爱学代码的学生】
什么是offsetof?
offsetof,程序语言,该宏用于求结构体中一个成员在该结构体中的偏移量。
头文件:stddef.h
宏形式:
size_t offsetof( structName, memberName )
说明:
1. 第一个参数是结构体的名字,第二个参数是结构体成员的名字。
2. 该宏返回结构体structName中成员memberName的偏移量。偏移量是size_t类型的。
代码实现如下:
typedef struct S
{
char a;
char c;
int b;
}S;
#define OFFSETOF(type,name) ((int)&(((type*)0)->name))
int main()
{
printf("%d\n", OFFSETOF(S, a));
printf("%d\n", OFFSETOF(S, c));
printf("%d\n", OFFSETOF(S, b));
return 0;
}边栏推荐
- LeetCode-98-验证二叉搜索树
- D. Game With Array
- Redis basic data type (Zset) ordered collection
- 二分查找 - 学习
- Supplementary questions for the training ground on September 11, 2021
- CANN编码的一些报错汇编
- 线性表的链式存储结构
- 使用 SAP UI5 CLI 命令行工具构建和运行 SAP UI5 应用
- In the future, cloud expansion technology is expected to be selected as a specialized, special and new enterprise in Shanghai
- 为什么需要微服务
猜你喜欢

Cdr2022 serial number coreldraw2022 green key

领先企业推进智慧财务的同款效率工具,赶快了解一下?

Codeforces Round #744 (Div. 3) 解题报告

Software test plan
![[Part 14] source code analysis and application details of completionservice class [key]](/img/41/9f5383d6eafb32723e29c15da3a1af.jpg)
[Part 14] source code analysis and application details of completionservice class [key]
![Analysis on the development history and market development status of China's system integration industry in 2020 [figure]](/img/3c/b53c2a3f59ff6784f128cb98a5a7a2.jpg)
Analysis on the development history and market development status of China's system integration industry in 2020 [figure]

LabVIEW Arduino electronic weighing system (project Part-1)

类和对象(1)

The network connection is normal, but Baidu web page can not be opened and displayed. You can't access this website solution

The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
随机推荐
焕新升级 | 创新,从云商店开始
Leetcode-110-balanced binary tree
Test plans and test cases
字符串复制函数
如何创建最简单的 SAP Kyma Function
建造者模式
How to create the simplest SAP kyma function
线性表的链式存储结构
Database daily question --- day 9: salesperson
CANN编码的一些报错汇编
LaTex实战笔记 3-宏包与控制命令
2021 Niuke multi school 5 double strings
[Part 14] source code analysis and application details of completionservice class [key]
Realize the same length of tablayout subscript and text, and change the selected font size
AC automata
Chain storage structure of linear table
LabVIEW controls Arduino to realize ultrasonic ranging (advanced chapter-5)
相对完善的单例模式
servlet获取表单数据
多态的所有特征