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

Richard Earnshaw
Mon Jul 5 12:56:00 GMT 2004

On Mon, 2004-07-05 at 13:45, Toralf Lund wrote:
> 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;
> *bPtr=-100;
> 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? 

Yes.  You can't take the address of a packed structure member and then
dereference it as a normal pointer.  If the underlying hardware/ABI only
supports aligned types then only pointers that are correctly aligned can
be dereferenced.  

> Is there another option or something that 
> might make the problem go away?

No.  GCC doesn't support pointer to unaligned fundamental type.


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

More information about the crossgcc mailing list