gcc structures

Jonathan Wakely jwakely.gcc@gmail.com
Sun Sep 8 14:32:00 GMT 2013


On 8 September 2013 14:42, JimJoyce wrote:
>
> My question  'Are Structures doublewoord aligned?' was not about the second
> half of the structure, but the beginning: an array of 9 ints.
> It appears, having decided to place them on a doubleword boundary, it then
> had to pad after the 9 ints to get back to an 8-byte boundary.

Yes, there's a "hole" in the middle of the struct.

> Was it pure mischance that the structure happened to start on a doubleword
> that the extra int was needed. Had it started 4 bytes later, there would be
> no padding?

If you think about it that question doesn't make sense. The layout of
a struct is always the same, irrespective of where an particular
instance of that struct happens to be positioned in memory.  A
struct's definition does not "start" anywhere in memory, only an
instance of the struct has an address.

> Or do structures always start on a doubleword?

It depends on the types in the struct and the ABI of the target platform.

There's plenty of information about this on the web, e.g.
http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86



More information about the Gcc-help mailing list