Memory alignment on i386

Jay Monkman jtm-list-rtems at
Fri Aug 27 19:59:17 UTC 2004

On Fri, Aug 27, 2004 at 03:26:16PM -0400, CamiloAlejo at wrote:

> What I really need is havig structure members 32-bit aligned. Having also every single variable 32-bit aligned could be a performance improvment, but is not that important now.

Or it might not be a performance improvement. If you're using the data
cache, it will likely be an anti-improvement.

If you find some way to make gcc force every struct member to be 32
bit aligned, you will almost certainly break something. If you blindly
change the alignment, the network code won't work. There are several
structures in the network stack that assume the members are packed,
but don't use the packed attribute. 

If you use some non-standard global alignment within your code, and
try to link to RTEMS with its standard alignment, it probably won't

If what you really need is to have _some_ structs to have a different
alignment, like for DMA or hardware registers or something similar,
declare the structs with every byte accounted for, and force them to
be packed:

     typedef struct {
         uint8_t   m1;           /* 0x00 */
         uint8_t   _res0[3];

         uint8_t   m2;           /* 0x04 */
         uint8_t   _res1;
         uint16_t  m3;           /* 0x06 */

         uint32_t  m4;           /* 0x08 */

         uint8_t   m5;           /* 0x0c */
         uint8_t   _res2;
         uint8_t   m6;           /* 0x0e */
         uint8_t   _res3;

     } example_t   __attribute__ ((packed));

If you have some data structure that must meet some external
requirement, _force_ it to meet the requirement - don't play games
with the compiler's alignment, and hope it will work.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <>

More information about the users mailing list