C中结构中的填充量是编译器相关还是定义良好?

C struct中的填充量是否在标准或编译器和/或目标体系结构中有明确定义.我无法在标准中找到答案.
它是实现定义的.从C99标准的第6.7.2.1节开始:

…Each non-bit-field member of a structure or union object is aligned in an implementation-defined
manner appropriate to its type…

…There may be unnamed
padding within a structure object, but not at its beginning…

编译器通常会选择适合底层硬件的布局(将内容对齐以便于从内存中读取等).

相关文章
相关标签/搜索