Reputation: 2785
Why are the offsets: 0 4 8 16 and 24? int = 4 bytes, double = 8 bytes. Why are there x's on the markings? How do you know when to use x's?
How does the other 2 structs and union offsets work?
Upvotes: 2
Views: 664
Reputation: 881363
Because a data type generally aligns to its size. So a four-byte integer will usually begin on a multiple of four bytes. This is not always necessary but it's often an efficiency method. It is necessary in some architectures in that they'll actually crash (raise some sort of error) if you try to access misaligned data.
The reason you have the x
characters is because they're the padding required to align the following data item.
Upvotes: 3