This is the mail archive of the
crossgcc@sources.redhat.com
mailing list for the crossgcc project.
See the CrossGCC FAQ for lots
more information.
arm-coff-gcc: -fpack-struct and non-word-aligned ints?
- From: Toralf Lund <toralf at procaptura dot com>
- To: crossgcc <crossgcc at sources dot redhat dot com>
- Date: Mon, 05 Jul 2004 14:45:58 +0200
- Subject: arm-coff-gcc: -fpack-struct and non-word-aligned ints?
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? 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, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com