m68k structure packing

Mike Stump mrs@wrs.com
Wed Oct 1 15:08:00 GMT 1997


> 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.



More information about the Gcc mailing list