[Bug c/27945] New: Packed struct of variable length has wrong size
alpt at freaknet dot org
gcc-bugzilla@gcc.gnu.org
Thu Jun 8 02:33:00 GMT 2006
Consider this test: http://hinezumilabs.org/alpt/test-pack.c
#define _PACKED_ __attribute__ ((__packed__))
int func(int levels)
{
struct foo {
u_char a;
int32_t b[levels];
struct timeval _PACKED_ c[levels];
u_int d[4];
}_PACKED_ pkt;
struct bar {
u_char a;
int32_t b[levels];
struct timeval c[levels];
u_int d[4];
}_PACKED_ pktII;
printf("pkt %d, foo %d\n", sizeof(pkt), sizeof(struct foo));
printf("pktII %d, bar %d\n", sizeof(pktII), sizeof(struct bar));
}
On a x86 with gcc-3.4.x/3.3.6 it prints:
pkt 65, foo 65
pktII 65, bar 65
(this is the right output)
while compiled for mips and runned on a BCM3302 (mips) with a gcc-3.4.4
it gives:
pkt 68, foo 68
pktII 68, bar 68
On a gentoo's 4.1.1 amd64:
pkt 104, foo 104
pktII 104, bar 104
On a x86 with the same version of gcc:
pkt 68, foo 68
pktII 68, bar 68
That's all ;)
--
Summary: Packed struct of variable length has wrong size
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alpt at freaknet dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27945
More information about the Gcc-bugs
mailing list