__attribute__((packed))

The keyword __attribute__ allows you to specify special attributes of struct and union types when you define such types. This is mostly encountered when designing code with particular care on memory footprint optimisation.  I have encountered this several times in some Apple headers while digging for documentation for my kext projects, and I thought it would be useful to explain it a bit. For example (from AppleUSBCDCCommon.h):

typedef struct
{
    UInt8 	bmRequestType;
    UInt8 	bNotification;
	UInt16	wValue;
	UInt16	wIndex;
	UInt16	wLength;
} __attribute__((packed)) Notification;

More reading:

Filed in Blog.

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *