This is the mail archive of the
ecos-devel@sources.redhat.com
mailing list for the eCos project.
Re: CYG_HAL_TABLE_END alignment
>>>>> "Bart" == Bart Veer <bartv@ecoscentric.com> writes:
Bart> struct fred {
Bart> cyg_uint32 a;
Bart> cyg_uint8 b[3];
Bart> }
Bart> On most architectures the compiler and linker will arrange for
Bart> the start of this structure to be aligned to a 4-byte boundary,
Bart> i.e. a byte of padding gets inserted. When the compiler
Bart> iterates through the table it thinks it has a fred[] array with
Bart> each entry properly aligned. The linker does not see an array,
Bart> it gets a number of individual variables, but it will align
Bart> each one's start to the appropriate boundary. So no problems so
Bart> far.
Yes, but the padding byte is "inside" the structure,
E.G. sizeof(struct fred) == 8 - isn't it?
Bart> Linker alignment only applies to the start of a structure, not
Bart> the end. Therefore when the linker places the end of the table
Bart> label this would appear immediately after the last entry,
Bart> without the padding. That is a bad idea so the end is
Bart> explicitly aligned in the code.
But immediately after the last entry is correct, as that is where the
next element would be placed.
To me the alignment directive should simply be removed from the
CYG_HAL_TABLE_END macro - or am I missing something?
Bart> P.S. I'll take a look at your I2C patches when I get a chance,
Bart> probably this weekend.
Thanks!
--
Bye, Peter Korsgaard