From: Andy Whitcroft Date: Thu, 23 Nov 2006 16:19:14 GMT Subject: Re: sizeof(struct ...) Message-ID: <4565CA02.20602@shadowen.org> In-Reply-To: <4565C8F4.6000606@lsrfire.ath.cx> René Scharfe wrote: > Erik Mouw schrieb: >> On Thu, Nov 23, 2006 at 04:45:09PM +0100, René Scharfe wrote: >>> 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. > > Does it add 1 byte after a and and 1 after b or two after b? > I suspect it's the latter case -- otherwise Gerrit's patch, > which started this thread, wouldn't help solve his problem. > Or the pad sizing follows complicated rules that I do not > understand at the moment. > > Time to look for an ARM emulator, it seems. Perhaps we can look and see what a portable application like gzip or bzip2 do in this situation. They must have the same problem.