当前位置:网站首页>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;
}边栏推荐
猜你喜欢

Top - k问题

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

The same efficiency tool for leading enterprises to promote smart finance. Let's have a quick look?

行而不辍,未来可期|云扩科技入选上海市专精特新企业

Latex combat notes 3- macro package and control commands

Uncover the secret of the popular app. Why is it so black

RPA丨首席财务官如何找到数字化转型“超级入口”?

Endnotex9 introduction and basic tutorial instructions

ESP32C3 Arduino库使用方法

How to use the transaction code sat to find the name of the background storage database table corresponding to a sapgui screen field
随机推荐
如何利用RPA机器人开启货代行业数字化转型第一步?
Leetcode-322- change exchange
Leetcode-43- string multiplication
Classes and objects (1)
Huawei equipment configuration h-vpn
206.反转链表
Look for leap years and see how many leap years I have had since I was born (I have had five)
Master of a famous school has been working hard for 5 years. AI has no paper. How can the tutor free range?
实验10 Bezier曲线生成-实验提高-控制点生成B样条曲线
多态的所有特征
[academic related] under the application review system, how difficult is it to study for a doctoral degree in a double first-class university?
Huawei equipment configuration hovpn
R language book learning 03 "in simple terms R language data analysis" - Chapter 7 linear regression model
二分查找 - 学习
Matlab: 文件夹锁定问题的解决
The college entrance examination is over, and life has just begun. Suggestions from a 10-year veteran in the workplace
类与对象(3)
Why is rpa+ low code a powerful tool to accelerate the digital transformation of finance?
【历史上的今天】6 月 11 日:蒙特卡罗方法的共同发明者出生;谷歌推出 Google 地球;谷歌收购 Waze
类和对象(1)