4 ms·
Many compilers insert padding bytes into the struct to ensure the fields are byte-aligned. What's worse, they often do this by default. The way this guy explai
by keeperofdakeys 15y ago
Many compilers insert padding bytes into the struct to ensure the fields are byte-aligned. What's worse, they often do this by default.
The way this guy explains it, he makes it sound optional, when it isn't. You can't use misaligned addresses on pretty much every piece of hardware. Compilers make a choice between time and effort, it is much easier to just pad a struct then try to juggle elements around until it takes up the least space. The onus is on the programmer to order their struts properly if they really care heavily about memory.