sizeof different in x86 and arm.
Richard Earnshaw
rearnsha@arm.com
Thu May 24 03:56:00 GMT 2001
> >-----Original Message-----
> >From: Cliff Tsai [ mailto:clifftsai@minecard.com.tw ]
> >Sent: 24 May 2001 11:42
>
>
> > I have a simple struct as follow
> >
> > struct test_align
> > {
> > unsigned char Name[21];
> > unsigned char Version[8];
> > };
> >
> > But on cygwin for x86,the sizeof(struct test_align) is 29;
> >
> > but on cygwin for arm,the sizeof(struct test_align) return 32
> >
> > WHY.
>
> I guess it's getting aligned. x86 is happy to read any datatype from
> any alignment address but I believe ARM likes things to be long word
> aligned, so it puts three padding bytes after Name[] so that the first
> byte of Version[] is aligned to a multiple of 4 bytes.
>
> I don't think it should really need to do this for chars, but I don't
> know ARM very well so I can't explain the motivation. However, the
> simplest way to fix it will be by using either the 'packed' or 'aligned'
> attributes - look them up in the gcc manual/info pages.
Not quite. The padding occurs at the end of the structure in this case.
Try:
struct a{
char a[3];
char b[4];
};
struct a x;
main()
{
printf("%d\n", &x.b[0] - &x.a[0]);
}
Even on the ARM this will print 3.
R.
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list