Hacker News new | ask | show | jobs
by senatorobama 2892 days ago
Why is struct ip_weight padded.. is it to make it word aligned on 64-bit platforms?
3 comments

in_addr_t is a 32 bit integer. On 64 bit archs this will usually result in a 32 bit padding for word alignment.
Padding is needed for two reasons: 8 bytes element need to start at multiple of 8 bytes address and to make the whole struct size multiple of the biggest member. This is needed for alignment once those structs are need to each other for example in an array.
To align 'weight' member on its size.
so the pad will be before the 'weight' member in memory?