-mstructure-size-boundary problem
Doug Evans
dje@transmeta.com
Tue Sep 12 16:48:00 GMT 2000
Shaun Jackman writes:
> I compiled the following snippet with
> -mstructure-size-boundary=8
> Unfortunately, sizeof( s) and sizeof( s0) both report 16 (should be 14).
> Through inspection with GCC, there's no padding between the members, so I
> assume the padding is being added to the end.
> I thought this is what -ms.s.b. was supposed to prevent.
Not quite.
> Help?
>
> typedef struct {
> int src;
> int dst;
> char mbz;
> char protocol;
> short length;
> short checksum;
> } s;
If you want to make this 14 bytes, you also have to mark it as packed.
typedef struct {
int src;
int dst;
char mbz;
char protocol;
short length;
short checksum;
} s __attribute__ ((packed)); // IIRC
-ms.s.b. applies after packing concerns. Note that on other
targets where structure-size-boundary is 8 (e.g. sparc)
sizeof (s0) == 16 which is what it should be. The padding
is for alignment requirements: if there's an array of them,
you want each array element properly aligned.
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list