This is the mail archive of the gcc@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]

Re: struct __attribute((packed));


Ralf Corsepius wrote:

On Fri, 2005-04-15 at 09:27 -0600, E. Weddington wrote:


It seems that GCC will interpret the above as e1 and e2 is packed within the struct somestruct so that e2 "immediately follows e1" (according to the manual). The packed attribute in this case does not refer to what e1 and e2 is pointing to.


That's what I found out by experimenting and is the reason why I am
asking. From what I see on i386,

struct entrystruct * entry __attribute__ ((packed));

is interpreted as "packed pointer to struct"
not as "pointer to packed struct",


I would interpret it that way too: packed pointer to struct. The "packed" attribute is on the variable itself, not the type of the variable (pointer to struct)

i.e. this construct is not meaningful.


Is it?

The manual says
"The |packed| attribute specifies that a variable or structure field should have the smallest possible alignment".


So it sounds like that:
struct entrystruct * entry __attribute__ ((packed));
by itself would mean that the variable entry has the smallest possible alignment. I don't know if that is meaningful just by itself or whether it is meaningful in your context.
And realise that I'm just postulating from looking at the manual. Somebody with more expertise would have to comment about this.


You've got the point - I am collecting ammunition to fight a stubborn
original author :-)


Yeah, if that author was thinking that the packed attribute applied to what the variable pointed to, then I would think that it is wrong usage of the attribute.
I would suggest pointing the author to the description of "packed" in the section on attributes of types:
<http://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Type-Attributes.html#Type-Attributes>


HTH
Eric


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