orpqK
orpqK

Reputation: 2785

alignment in assembly, how does each get its offset?

This is a question I was working on, but I only want to know why the offsets are the way it is (the little red numbers)

pic

Can someone explain to me why in struct s1, the offset went from 0->4->8? From what I understand, since char is 1 byte, there are 3 char's. so it's 3 bytes plus 1, to satisfy alignment. But why does it go from 4 to 8, at union u1 b?? Does union has 4 bytes? why?

Upvotes: 2

Views: 417

Answers (1)

JasonD
JasonD

Reputation: 16582

The union is 4 bytes because that is the size of the largest element it contains, namely a pointer (this must be a 32-bit platform)

Upvotes: 2

Related Questions