[英]How to calculate padding in C struct
While I understand how padding generally works in a C struct, I struggle to understand how inner struct are padded.虽然我了解填充通常如何在 C 结构中工作,但我很难理解内部结构是如何填充的。 Example:
例子:
struct inner
{
int a;
}
struct outer
{
char a;
struct inner b;
}
How is the padding between member outer.a
and member outer.b
calculated? member
outer.a
和 member outer.b
之间的 padding 是如何计算的?
How is the padding of the end of struct outer
calculate when the data type of member inner.a
changes from int
to short
or double
?当成员
inner.a
的数据类型从int
变为short
或double
时,struct outer
末尾的填充如何计算?
What are the implications of calculating these paddings in a 32 bit architecture versus a 64 bit one?在 32 位架构和 64 位架构中计算这些填充有什么含义?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.