Page 1 of 1
struct information
Posted: Mon Mar 10, 2003 5:37 pm
by stonedzealot
So I'm looking through some code, as I often do, and I realize that a lot of the structs have weird things after the elements are closed, but before the name ala:
Code: Select all
typedef struct
{
word low_offset; //low 8 bytes of handler offset
word selector; //handler's selector
word settings; //kind of entry
word high_offset; //high 8 bytes of handler offset
} __attribute__ ((packed)) x86_interrupt;
The contents aren't a problem (of course) but what is __attribute__ ((packed))? Rather than answering this question straight out, I'd prefer if someone could point me to where I could get the information...
Re:struct information
Posted: Mon Mar 10, 2003 5:44 pm
by Tim
Where to get the information: info gcc. Good luck.
It's easier if I (we) explain this particular one. The __attribute__(()) syntax is a gcc extension; packed means 'don't add padding to align the members of this struct'. It's probably not necessary on this structure, since gcc will (should) align those words on word boundaries, but it gets more important with, say, file system structures.
Re:struct information
Posted: Mon Mar 10, 2003 8:43 pm
by stonedzealot
Thanks alot! But in this case it is needed because these a written straight to the Interrupt Descriptor Tables and need to be accessed one after the other, with no spacing. Anyway, thanks for your help...
Re:struct information
Posted: Wed Mar 12, 2003 1:26 pm
by Tim
In this case it's not needed because gcc aligns those words to 16-bit boundaries.
Roughly, the alignment rules are:
[o] chars are aligned to 1-byte boundaries
[o] shorts to 16 bits
[o] longs/ints to 32 bits
[o] doubles to 64 bits
[o] structures to the strictest of its field's alignment requirements (not sure about this)
So a structure consisting solely of words won't have any spacing between them.
Re:struct information
Posted: Sat Mar 15, 2003 9:55 pm
by stonedzealot
Ah, you've got me there. Thanks alot!