On Fri, Feb 10, 2006 at 04:56:20PM +0100, Nicolas DICHTEL wrote: > Hi all, > > here is the result on ARM of my little program: > > [EMAIL PROTECTED]:/usr/admin# ./test2 > 4 5 6 8 > 2 3 4 6 > > > Is it normal to add an attribute __packed__ on each union{} > contained in a structure, or is it a bug of my compiler ? > On X86, this kind of structure has always the good size.
As Andrew alluded to, this is a quirk of the ARM APCS (arm-linux's ABI). It's changed in the newer ARM AAPCS (arm-linux-gnueabi). > union u { > u_int8_t a[2]; > u_int16_t b; > }; The size of this type is four on that ABI. It doesn't matter if you pack a structure containing this; that eliminates padding in the structure, but doesn't change the type or size of the union. -- Daniel Jacobowitz CodeSourcery