public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* packed structures
@ 2003-12-08 14:01 Frank Cornelis
  2003-12-10  7:51 ` Jim Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Frank Cornelis @ 2003-12-08 14:01 UTC (permalink / raw)
  To: gcc-bugs; +Cc: Frank Cornelis

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
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: packed structures
  2003-12-08 14:01 packed structures Frank Cornelis
@ 2003-12-10  7:51 ` Jim Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Wilson @ 2003-12-10  7:51 UTC (permalink / raw)
  To: Frank Cornelis; +Cc: gcc-bugs

Frank Cornelis wrote:
> When I mark a structure with __attribute__((packed)) and that structure
> has inner-structs, these inner-structs no longer are packed.

attribute packed only affects the type that it is applied to.  It does 
not affect outer or inner types.  As far as I know, it has always worked 
this way.

If we changed attribute packed to affect inner types, then we would be 
reducing the power of this feature, as then it would no longer be 
possible to unpacked structures inside packed structure.  That is a 
reasonable thing that some users might want to do, so we should not 
exclude the possibility.

If you have a structure with inner types that you also want packed, then 
you must apply attribute packed to the inner types.  An alternative 
would be to enable pragma pack across the structure, but you have to be 
careful to disable it after the structure, so it is usually less convenient.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-12-10  7:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-08 14:01 packed structures Frank Cornelis
2003-12-10  7:51 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).