The __attribute__((packed)) keyword is applied to a struct.
IN
typedef struct { int a; } baz __attribute__((packed));
typedef associates baz with a structure - attributes appear after and nothing is applied - gcc ignores it. To fix this, allow typedef to bind the entire structure declaration, including the attribute, by placing baz after the attribute:
typedef struct { int a; } __attribute__((packed)) baz;
In the second example, the structure declaration is incorrect
struct qux __attribute__((packed)) { int a; }
how quz should appear after the attribute:
struct __attribute__((packed)) qux { int a; }
It is usually better to let the compiler optimize the structure and align the internal elements in memory so that the processor processes them more efficiently.
Packing the structure, however, can be important when creating a data structure that needs to be packaged to cope, for example, with the requirement of a driver.
source share