This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
packed structures
- From: Frank Cornelis <Frank dot Cornelis at elis dot ugent dot be>
- To: gcc-bugs at gcc dot gnu dot org
- Cc: Frank Cornelis <Frank dot Cornelis at elis dot ugent dot be>
- Date: 08 Dec 2003 15:00:56 +0100
- Subject: packed structures
Hi,
When I mark a structure with __attribute__((packed)) and that structure
has inner-structs, these inner-structs no longer are packed. The correct
semantics for this would be that they inherit this packed property since
people only want to use the packed attribute to model system structures
like for example my pci_slot_entry_struct. (See below for the example)
Thus the entire structure and all its sub-structs need to be packed.
Please CC me,
Frank.
#include <stdio.h>
struct pci_slot_entry_struct {
unsigned char pci_bus;
unsigned char pci_device;
struct {
unsigned char link;
unsigned short irq_bitmap;
//} __attribute__((packed)) ints[4];
} ints[4];
unsigned char physical_slot;
unsigned char reserved;
} __attribute__((packed));
int main() {
printf("sizeof %d\n", sizeof(struct pci_slot_entry_struct));
// should be 16
}