Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@birdulon @kirby if you aren't doing it like gcc you're wrong
OK but USUALLY
It'll start with the topmost element
That's always going to be aligned, so it never moves
The next element in the struct It'll grab, and align on the nearest aligned memory location for that elements size
So if element 1 is a byte, and element 2 is an int, element 0 will be at +0, element 1 will try to go to +1, but that isn't aligned. The nearest aligned location for an int is +4, so the compiler puts it there instead, and the previous three bytes are padding. If it were a short, it'd be put in +2, a long +8
The compiler then just keeps walking through the struct until it's done
The end padding tbh isn't too important unless you're worried about distances outside the struct, or arrays of struct