Wiki Markup |
---|
The size of a structure is not always equal to the sum of the sizes of its members. According to Section 6.7.2.1 of the C99 standard, "There may be unnamed padding within a structure object, but not at its beginning" \[[ISO/IEC 9899:1999|AA. References#ISOBibliography#ISO/IEC 9899-1999]\]. |
This is often referred to as structure padding. Structure members are arranged in memory as they are declared in the program text. Padding may be added to the structure to ensure the structure is properly aligned in memory. Structure padding allows for faster member access on many architectures.
...
Wiki Markup |
---|
This noncompliant code example assumes that the size of {{struct buffer}} is equal to the sum of the size of its individual components, which may not be the case \[[Dowd 06|AA. References#DowdBibliography#Dowd 06]\]. The size of {{struct buffer}} may actually be larger due to structure padding. |
...
Wiki Markup |
---|
\[[Dowd 06|AA. References#DowdBibliography#Dowd 06]\] Chapter 6, "C Language Issues" (Structure Padding 284-287) \[[ISO/IEC 9899:1999|AA. References#ISOBibliography#ISO/IEC 9899-1999]\] Section 6.7.2.1, "Structure and union specifiers" \[[Sloss 04|AA. References#SlossBibliography#Sloss 04]\] Section 5.7, "Structure Arrangement" |
...