arm-coff-gcc: -fpack-struct and non-word-aligned ints?

Toralf Lund
Mon Jul 5 12:46:00 GMT 2004

I'm building some code with -fpack-struct on ARM cross-gcc because an 
old API expects it. This mostly works fine, but it turns out that I 
sometimes get word-alignment issues that I never saw on the platform I'm 
porting from (M68k, a completely different compiler.) I sometimes get 
int-type struct-members at addresses that are not word-aligned, although 
they are always *halfword*-aligned. In some, but not all (I'm not sure 
about the exact conditions) cases where this happens, I get into trouble 
if I assign a value to the variable via it's address. Simply put, it 
looks like the address is rounded down to the nearest word-boundary, so 
that if I do something like

struct somestruct {
    short a;
    int b;
[ ... ]

struct somestruct value;

[ ... ]
int *bPtr=&value.b;


the assignment will (at least under certain conditions) not actually 
write to all 4 bytes of value.b's memory area, but rather value.a and 
the two first bytes of value.b.

Is this expected to happen? Is there another option or something that 
might make the problem go away?

Note: I think I know several ways arounf the problem in my actual 
program - in fact I may even be able to rewrite everything so that 
-fpack-struct is not necessary - but I'd really like to know what is 
going on first.

- Toralf

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

More information about the crossgcc mailing list