Page 2 of 2

Re: Making bootsector for USB pen

Posted: Sun Jun 22, 2008 12:38 pm
by Korona
kmcguire wrote:
Korona wrote:I don't know if that causes any problem in this case but generally structures that the compiler must not align or reorganize should be marked with __attribute((__packed__)).
Structures that have member fields that you do not want padded to maintain alignment on word boundaries need to use the __attribute__((__packed__)) expression. The C compiler should never reorganize the members of a structure! The padding increases the performance of data access (if you have ever noticed inside the manuals for a processor's instruction set it will hint to performance decreases on unaligned memory accesses for some stuff).

The alignment of the structure it's self comes from it's creation. Such that if you create the structure as a local variable then it is automatically aligned by the stack's word size. While, if you create the structure using a pointer, then the structure may or may not be aligned no matter if you used the __packed__ attribute or not.
Yes, of course the __packed__ attribute only affects internal alignments. Are you sure that the C compiler is not allowed to reorganize the members of the structure? I don't think that is part of the ANSI C standard though I did not check that.