3 ms·
> One might assume that the compiler puts all its members directly behind each other in memory with no gaps in between and that the size of each structure is ex
by juunpp 3y ago
> One might assume that the compiler puts all its members directly behind each other in memory with no gaps in between and that the size of each structure is exactly the same as the sum of the sizes of all of its members. Such a structure is called a packed structure:
> This is NOT how a compiler usually lays out a structure in memory.
Just explain how it works instead of assuming that the reader is making an (incorrect) assumption. I think you're caught making that assumption because you've introduced the topics in a non-optimal order.
I would split up "Element Order and Addressing" and remove the picture there because it's misleading. You can talk about addressing without explaining how the struct is laid out in memory. You don't even need structs to explain addressing ("& takes the address of an object"). Then, once you've introduced basic addressing and struct alignment/padding, you could introduce addressing of struct fields. But I suspect it won't have much value at that point because the logistics will be a natural consequence of the earlier topics.