On Thu, Nov 24, 2011 at 11:33:09AM +0100, Harald Welte wrote:
normally, the compiler will lay out the structure in a way that optimizes accesses to members. So e.g. on an ARM, a
struct { uint8_t byte1; uint8_t byte2; };
will very likely contain 3 bytes padding between the two uint8 values in order to make sure no unaligned loads/stores will be required.
However, if you change that to '__packed', the padding will not be generated and any access to struct members will need to deal with unaligned accesses, which can be inflating the code size considerably.
thanks for pointing that out. It's actually obvious after a moment of thinking.
One additional thought on the switch/enum situation and initialisation: what about adding an additional member to the enum, let's say VOID and instances of the enum are initialised to that. A switch statement that handles this enum gets a case for VOID which produces a runtime warning, much like a default case. this way the compiler is happy, because the variable is initialised and also tells you when enum values are not handled.