Hot of the press at Dr. Dobb's:
Padding and Rearranging Structure Members
By Dan Saks
... Multibyte objects often have an alignment ... a "requirement that objects of a particular type be located on storage boundaries with addresses that are particular multiples of a byte address". The Standard leaves it up to each target processor to specify its alignment requirements. That is, a processor might require that a 4-byte integer or pointer referenced as a single object be word aligned — at an address that's a multiple of four. A processor also might require that an 8-byte floating-point number be word aligned, or maybe even double-word aligned — at an address that's a multiple of eight.
According to the C Standard, a program that attempts to access an improperly aligned object produces undefined behavior. This means that the program is in error, but the exact consequences of that error are platform-dependent. With many processors, an instruction that attempts to access improperly aligned data issues a trap. With other processors, an instruction that accesses misaligned data executes properly but uses up more cycles to fetch the data than if the data were properly aligned...
Add a Comment
Comments are closed.