当前位置:网站首页>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;
}边栏推荐
- Take off efficiently! Can it be developed like this?
- 建造者模式
- Add anti debugging function to game or code (application level)
- R语言相关文章、文献整理合集(持续更新)
- Parker plunger pump pv180r1k1t1nmmc
- Customer information management software
- Redis Foundation
- Flutter series: detailed explanation of container layout commonly used in flutter
- C语言实现八种排序(3)
- 学习位段(1)
猜你喜欢

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

Leetcode-129- sum of numbers from root node to leaf node

Leetcode-76- minimum covering substring

【学术相关】申请审核制下,到双一流大学读博的难度有多大?

EndnoteX9简介及基本教程使用说明

C语言实现迷宫问题

RPA丨首席财务官如何找到数字化转型“超级入口”?
![BZOJ3189 : [Coci2011] Slika](/img/46/c3aa54b7b3e7dfba75a7413dfd5b68.png)
BZOJ3189 : [Coci2011] Slika

类和对象(2)

R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
随机推荐
Redis transaction
Classes and objects (3)
剑指Offer 29.顺时针打印矩阵
The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
C语言实现八种排序(2)
多态的所有特征
206.反转链表
Endnotex9 introduction and basic tutorial instructions
Usage of esp32c3 Arduino Library
Carry and walk with you. Have you ever seen a "palm sized" weather station?
自定义实现offsetof
实验10 Bezier曲线生成-实验提高-控制点生成B样条曲线
R语言书籍学习03 《深入浅出R语言数据分析》-第七章 线性回归模型
189. rotation array
Binary search - Learning
Codeworks round 739 (Div. 3) problem solving Report
Cdr2022 serial number coreldraw2022 green key
69. x的平方根
Redis basic data type (Zset) ordered collection
快速排序的优化