This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]