当前位置:网站首页>C language structure
C language structure
2022-06-12 13:24:00 【shlyyy】
C Language structure
Preface
Structure alignment is divided into : Structure member variables Alignment and Structural variable Alignment of
One 、 Structure member variable alignment
The alignment value of the structure member variable is
MemberAlign = Min(Zp, sizeof(MemberType))
among Zp Alignment values specified for compilation options .MemberType Is the type of the member , If the member variable is an array ,MemberType That's the type of the array .
Structure member variables Distance from the first address of the structure The migration
MemberOffsetIs the member'sMemberAlignInteger multiple . namelyMemberOffset % MemberAlign == 0
Two 、 Alignment of structural variables
The alignment value of the structure variable is
StructAlign = Min(Zp, Max(sizeof(MemberType1),...))
Structure size
StructSizeyesStructAlignInteger multiple . namelyStructSize % StructAlign == 0
3、 ... and 、 Structure addressing mode
Structural members Address = The first address of the structure variable + The offset of the structure member variable MemberOffset
struct s;
s.member = *(MemberType*)((int)(&s) + MemberOffset);
struct* ps;
ps->member = *(MemberType*)((int)ps + MemberOffset);
// If ps by NULL, You can calculate the offset of the member according to this formula , It's the following offsetof macro
offsetofAccording to the passed structure and member variables , Calculate the offset of the structure member variable
#include <stddef.h>
#define offsetof(s,m) ((size_t)&(((s*)0)->m))
边栏推荐
- Unittest framework
- Deploy opengauss database based on Huawei cloud Kunpeng elastic ECS [Gauss is not a mathematician this time]
- 在 Debian 10 上独立安装MySQL数据库
- Multi source BFS problem template (with questions)
- imagemagick:a gentle introduction to magick++
- Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo
- Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
- JSP jump problem, unable to display database data, and unable to jump
- 1001:Hello,World
- 【云原生 | Kubernetes篇】深入了解Ingress
猜你喜欢

C#DBHelper_FactoryDB_GetConn

移动应用出海的“新大陆”

leetcode 47. Permutations II 全排列 II(中等)

安装MySQL时出错,照着下面这个链接,做到cmd就不行了

Pytorch to onnx, onnxruntime reasoning in mmclas

单向环形链表实现约瑟夫环

The goods are full. You must take this knowledge

How to solve the problem of data table query error when SQLite writes the registration function?

How to balance multiple losses in deep learning?

442 authors, 100 pages! It took Google 2 years to release the new benchmark big bench | open source
随机推荐
移动应用出海的“新大陆”
Innovation training (XII) project summary
What if the MySQL installation on the apple computer is completed and cannot be found
Redis message queue repeated consumption
Successful job hopping Ali, advanced learning
[EDA] chip layout design: VLSI layout design using electric
imagemagick:a gentle introduction to magick++
Getting started with NVIDIA Jetson nano Developer Kit
torch_ geometric message passing network
[cloud native | kubernetes] kubernetes networkpolicy
How to solve the problem of data table query error when SQLite writes the registration function?
Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo
NVIDIA Jetson Nano Developer Kit 入门
The problem of Joseph in Informatics
Openstack network
Pre research of image scanning tool
5V升压到12.6V的锂电池充电IC芯片方案FS4062B
嵌入式系统硬件构成-嵌入式系统硬件体系结构
创新实训(十)高级界面美化
Design virtual network to realize communication between virtual machine instance and external network