This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
How to stop gcc padding structs???
- To: ecos-discuss at sources dot redhat dot com
- Subject: [ECOS] How to stop gcc padding structs???
- From: Grant Edwards <grante at visi dot com>
- Date: Sun, 28 Jan 2001 12:40:59 -0600
I'm again fighting with gcc trying (and failing) to get it to
stop putting padding bytes into structs. Have any eCosians
figured out how to prevent gcc from padding structs?
I ran into this problem before and gave up, finally having to
use hand-calculated constants instead of "sizeof (struct foo)"
in numerous places. For example, it's impossible to define an
Ethernet header structure that ends up having a size of 14
bytes!
In the following example, gcc insists that each of the "high"
structs occupies four bytes despite my putting a "packed"
attribute evryplace that doesn't generate a syntax warning.
typedef struct
{
volatile unsigned char data __attribute__((packed));
volatile unsigned char _xxx __attribute__((packed));
} high __attribute((packed));
typedef struct
{
high a __attribute__((packed));
high b __attribute__((packed));
high c __attribute__((packed));
} tDemo __attribute__((packed));
tDemo foo;
void *addr[] =
{
&foo,
&foo.a,
&foo.b,
&foo.c
};
testit: file format elf32-bigarm
Disassembly of section .data:
00008000 <addr>:
8000: 00008010 andeq r8, r0, r0, lsl r0
8004: 00008010 andeq r8, r0, r0, lsl r0
8008: 00008014 andeq r8, r0, r4, lsl r0
800c: 00008018 andeq r8, r0, r8, lsl r0
--
Grant Edwards
grante@visi.com