''Part of the WritingPortableDrivers section''[[BR]] The gcc compiler typically aligns individual fields of a structure on whatever byte boundary it likes in order to provide faster execution. For example, consider this code and resulting output: {{{ #!cplusplus #include #include struct foo { char a; short b; int c; }; #define OFFSET_A offsetof(struct foo, a) #define OFFSET_B offsetof(struct foo, b) #define OFFSET_C offsetof(struct foo, c) int main () { printf ("offset A = %d\n", OFFSET_A); printf ("offset B = %d\n", OFFSET_B); printf ("offset C = %d\n", OFFSET_C); return 0; } }}} Running the program gives: {{{ offset A = 0 offset B = 2 offset C = 4 }}} The output shows that the compiler aligned fields {{{b}}} and {{{c}}} in {{{struct foo}}} on even byte boundaries. This is not a good thing when we want to overlay a structure on top of a memory location. Typically driver data structures do not have even byte padding for the individual fields. Because of this, the gcc attribute {{{((packed))}}} is used to tell the compiler not to place any "memory holes" within a structure. If we change the struct foo structure to use the packed attribute like this: {{{ #!cplusplus struct foo { char a; short b; int c; } __attribute__((packed)); }}} Then the output of the program changes to: {{{ offset A = 0 offset B = 1 offset C = 3 }}} Now there are no more memory holes in the structure. This packed attribute can be used to pack an entire structure, as shown above, or it can be used only to pack a number of specific fields within a structure. For example, the struct usb_ctrlrequest is defined in include/usb.h as the following: {{{ #!cplusplus struct usb_ctrlrequest { __u8 bRequestType; __u8 bRequest; __le16 wValue; __le16 wIndex; __le16 wLength; } __attribute__ ((packed)); }}} This ensures that the entire structure is packed, so that it can be used to write data directly to a USB connection. But the definition of the struct usb_endpoint_descriptor looks like: {{{ #!cplusplus struct usb_endpoint_descriptor { __u8 bLength __attribute__((packed)); __u8 bDescriptorType __attribute__((packed)); __u8 bEndpointAddress __attribute__((packed)); __u8 bmAttributes __attribute__((packed)); __le16 wMaxPacketSize __attribute__((packed)); __u8 bInterval __attribute__((packed)); __u8 bRefresh __attribute__((packed)); __u8 bSynchAddress __attribute__((packed)); unsigned char *extra; /* Extra descriptors */ int extralen; }; }}} This ensures that the first part of the structure is packed and can be used to read directly from a USB connection, but the extra and extralen fields of the structure can be aligned to whatever the compiler thinks will be fastest to access.