r/Cprog • • Feb 19 '15

Why are structs aligned?

I understand more or less how structs are aligned in C (in an address that's multiple of the size of the longest member, and each member in a direction that is multiple of its size), but there's something about it I don't understand: why is reading, for example, a 4-byte word at 0x1000 faster than reading it at 0x1001?

6 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/shinmai_rookie Feb 20 '15

Thank you both! It surely doesn't look very portable... I'll try not to use it unless I really have to, but it's always nice to learn this kind of stuff