* -mstructure-size-boundary problem
@ 2000-09-12 15:30 Shaun Jackman
2000-09-12 16:48 ` Doug Evans
0 siblings, 1 reply; 2+ messages in thread
From: Shaun Jackman @ 2000-09-12 15:30 UTC (permalink / raw)
To: crossgcc
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.
Help?
typedef struct {
int src;
int dst;
char mbz;
char protocol;
short length;
short checksum;
} s;
int
main()
{
s s0;
int i;
i = sizeof( s);
i = sizeof( s0);
return 0;
}
--
host=i686-pc-linux-gnu
target=arm-elf
--
Thanks,
Shaun
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* -mstructure-size-boundary problem
2000-09-12 15:30 -mstructure-size-boundary problem Shaun Jackman
@ 2000-09-12 16:48 ` Doug Evans
0 siblings, 0 replies; 2+ messages in thread
From: Doug Evans @ 2000-09-12 16:48 UTC (permalink / raw)
To: shaunj; +Cc: crossgcc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-09-12 16:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-12 15:30 -mstructure-size-boundary problem Shaun Jackman
2000-09-12 16:48 ` Doug Evans
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).