This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: m68k structure packing
- To: pbarada at wavemark dot com, wilson at cygnus dot com
- Subject: Re: m68k structure packing
- From: mrs at wrs dot com (Mike Stump)
- Date: Wed, 1 Oct 1997 15:07:47 -0700
- Cc: egcs at cygnus dot com
> Date: Wed, 1 Oct 1997 11:52:44 -0400
> From: Peter Barada <pbarada@wavemark.com>
> To: wilson@cygnus.com
> If you have a short in the struct:
> struct {
> short b;
> char a;
> } z, list[10];
> then sizeof(z) could be 3 but is 4 due to alignment requirements(i.e
> malloc(n*sizeof(z))) and sizeof(list) is 40.
Is this fact, or theory? On the sparc, which is unaffacted by my
change, with -fpack-struct we get 3 bytes.
struct foo1
{
short b;
char a;
} f[2] = {{ 1, 2}, {3, 4}}, b;
short i, *ip;
main () {
ip = &f[1].b;
i = *ip;
}
fails. My patches may help the m68k fail in the same way I suspect.
> And obviously if you have a long, then the sizeof has to round up to a
> long.
That isn't what the code today does.
> Even if you pack the structure, you have to allow for alignment
> requirements.
That isn't what the code today does.
This issue is 100% independent of the issue I was interested in, but
since we are talking about it, it makes since to bring this issue up,
and see what others think about it.
Should the above code fail at runtime? (You have to have a
STRICT_ALIGNMENT machine, pack a structure, and you may have to use
int or long or float or double to make it fail). If not, should we
make it work by aligning it or by requiring what the pointer points to
is a packed short, then on dereference of a pointer to a packed short,
we could know to do byte accesses.