C语言中结构的填充量是否依赖于编译器或定义得当? [英] Is the amount of padding in structure in C is Compiler dependent or well defined?

查看:61
本文介绍了C语言中结构的填充量是否依赖于编译器或定义得当?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是C struct中的填充量,在标准或编译器和/或目标体系结构相关方面定义良好.我找不到标准的答案.

Is the a amount of padding in C struct well defined in standards or compiler and/or target architecture dependent. I could not find an answer in the standards.

推荐答案

它是实现定义的.根据C99标准的6.7.2.1节:

It is implementation-defined. From section 6.7.2.1 of the C99 standard:

...结构或联合对象的每个非位字段成员在实现定义中对齐 适合其类型的方式...

...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...

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

The compiler will typically choose an arrangement that suits the underlying hardware (aligning things to be easy to read from memory, etc.).

这篇关于C语言中结构的填充量是否依赖于编译器或定义得当?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆