Darren Rook wrote: > On Fri, Jan 16, 2009 at 10:59 AM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > >>> Then why is attribute((packed)) provided? I really don't see a use >>> for it. Why not rename it to __attribute__((addressviolation))? >> The potential address violation only occurs when you take the address >> of a field and pass it to another function. There are many ways to >> use structures without taking the address of a field. > > So my example > > handle(&t.field2); > > has the potential to create an address violation, but these > assignments do not(?): > > t.field2 = <some value> > t->field2 = <some value> That's right. The important thing to realize is that the type of &field2 in struct test { UINT8 field1; UINT16 field2; UINT8 field3; } __attribute__((__packed__)); is not UINT16 *; the compiler knows that it's an element of a packed struct, and generates code accordingly. The correct procedure is always to pass the address of the whole struct. Andrew.