Mark Butcher

packed struct difficults (CW 6.3)

Discussion created by Mark Butcher on Feb 10, 2008
Latest reply on Feb 12, 2008 by Mark Butcher
Hi All

I have a struct which is constructed from other structs. Each struct is made up of only bytes.



typedef struct stUSB_CONFIGURATION_DESCRIPTOR_COLLECTION
{
    USB_CONFIGURATION_DESCRIPTOR config_desc;
    USB_INTERFACE_DESCRIPTOR     interface_desc;
    USB_TEST_DESCRIPTOR               test_desc;
    USB_ENDPOINT_DESCRIPTOR      endpoint_desc;
} USB_CONFIGURATION_DESCRIPTOR_COLLECTION;


An example of the individual structs:
typedef struct _PACK stUSB_ENDPOINT_DESCRIPTOR
{
    unsigned char          bLength;                                      // descriptor size in bytes
    unsigned char          bDescriptorType;                              // device descriptor
    unsigned char          bEndpointAddress;                             // direction and address of endpoint
    unsigned char          bmAttributes;                                 // endpoint attributes
    unsigned char          wMaxPacketSize[2];                            // endpoint FIFO size
    unsigned char          bInterval;                                    // polling interval in ms
} USB_ENDPOINT_DESCRIPTOR;



The problem that I have is that there are additional bytes inserted between the individual strucs - eg.
USB_ENDPOINT_DESCRIPTOR is 7 bytes in size (as are others) and each time a struct is uneven, the next is moved to start at an even boundary - thus the complete block is larger than expected and its content is not correctly recognised in use-

I have tried #pragma options align=packed but this didn't have any effect - the situation remained.

Does anyone know how I can force the desired results?

Regards

Mark Butcher

www.uTasker.com

Outcomes