This is the mail archive of the
mailing list for the GCC project.
Re: How to stop gcc padding structs???
On Mon, Jan 29, 2001 at 10:26:40AM +0000, Richard Earnshaw wrote:
> > I'm again fighting with gcc trying (and failing) to get it to
> > stop putting padding bytes into structs. Has anybody 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!
> Relying on sizeof to do this is *very* non-portable.
It's a device driver for a specific board. It doesn't really
need to be portable.
> typedef struct
> volatile unsigned char data;
> volatile unsigned char _xxx;
> } __attribute((packed)) high;
Several people suggested that, but it didn't make any
volatile unsigned char data __attribute__((packed));
volatile unsigned char _pad __attribute__((packed));
} __attribute__((packed)) high __attribute__((packed)) ;
high a __attribute__((packed));
high b __attribute__((packed));
high c __attribute__((packed));
} __attribute__((packed)) tDemo __attribute__((packed)) ;
void *addr =
int sizeofHigh = sizeof (high);
testit: file format elf32-bigarm
Disassembly of section .data:
8000: 00008018 andeq r8, r0, r8, lsl r0
8004: 00008018 andeq r8, r0, r8, lsl r0
8008: 0000801c andeq r8, r0, r12, lsl r0
800c: 00008020 andeq r8, r0, r0, lsr #32
8010: 00000004 andeq r0, r0, r4