From: Erik Mouw Date: Thu, 23 Nov 2006 15:54:31 GMT Subject: Re: sizeof(struct ...) Message-ID: <20061123155431.GD6581@harddisk-recovery.com> In-Reply-To: <4565C205.8050300@lsrfire.ath.cx> On Thu, Nov 23, 2006 at 04:45:09PM +0100, Ren? Scharfe wrote: > Andy Whitcroft schrieb: > > You see packing attributes applied to similar things in the kernel. > > Perhaps they are relevant here? > > Is there not some kind of attribute thing we can apply to this structure > > to prevent the padding? You see that in the kernel from time to time. > > > > struct foo { > > } __attribute__((packed)); > > Yes, that would be nice, but unfortunately __attribute__ is no standard > C. There is no standard C way to pack structures. Some compilers use #pragma's, gcc uses __attribute__((packed)). > Is there really a compiler that inserts padding between arrays of > unsigned chars? Yes, that compiler is called "gcc". #include struct foo { unsigned char a[3]; unsigned char b[3]; }; int main(void) { printf("%d\n", sizeof(struct foo)); return 0; } On i386 that prints 6, on ARM it prints 8. Erik -- +-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --