当前位置:网站首页>Custom implementation offsetof
Custom implementation offsetof
2022-06-11 21:54:00 【Code loving students】
What is? offsetof?
offsetof, Programming language , This macro is used to find the offset of a member in the structure .
The header file :stddef.h
Macro form :
size_t offsetof( structName, memberName )
explain :
1. The first parameter is the name of the structure , The second parameter is the name of the structure member .
2. The macro returns the structure structName Member of the memberName The offset . The offset is size_t Type of .
The code implementation is as follows :
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;
}边栏推荐
- Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
- bzoj3188 Upit
- How to view the installation date of the win system
- 高考结束,人生才刚刚开始,10年职场老鸟给的建议
- 行而不辍,未来可期|云扩科技入选上海市专精特新企业
- In the post epidemic era, how can enterprise CIOs improve enterprise production efficiency through distance
- Why microservices are needed
- Matlab: 文件夹锁定问题的解决
- Binary search - Learning
- R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
猜你喜欢

每日一题 - 罗马数字转整数

R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest

189. rotation array

【历史上的今天】6 月 11 日:蒙特卡罗方法的共同发明者出生;谷歌推出 Google 地球;谷歌收购 Waze

Classes and objects (2)

Leetcode-98- validate binary search tree

Leetcode-104- maximum depth of binary tree

Why is rpa+ low code a powerful tool to accelerate the digital transformation of finance?

Classes and objects (1)

如何查看win系统的安装日期
随机推荐
How to use RPA robot to start the first step of digital transformation of freight forwarding industry?
二分查找 - 学习
华为设备配置HoVPN
Leetcode-98- validate binary search tree
RPA super automation | nongnongji and cloud expansion accelerate financial intelligent operation
【历史上的今天】6 月 11 日:蒙特卡罗方法的共同发明者出生;谷歌推出 Google 地球;谷歌收购 Waze
Take off efficiently! Can it be developed like this?
快速排序的优化
In the future, cloud expansion technology is expected to be selected as a specialized, special and new enterprise in Shanghai
Relatively perfect singleton mode
238.除自身以外数组的乘积
Why microservices are needed
2022-02-28(1)
科普 | NFT的类型有哪些(上)
Look for leap years and see how many leap years I have had since I was born (I have had five)
Uncover the secret of the popular app. Why is it so black
R语言书籍学习03 《深入浅出R语言数据分析》-第七章 线性回归模型
行而不辍,未来可期|云扩科技入选上海市专精特新企业
类和对象(1)
Codeforces Round #742 (Div. 2) F. One-Four Overload