In usb_misc.h, STRUCT_UNPACKED is defined as follows.
#if defined(__ICCARM__) #ifndef STRUCT_PACKED #define STRUCT_PACKED __packed #endif #ifndef STRUCT_UNPACKED #define STRUCT_UNPACKED #endif #elif defined(__GNUC__) #ifndef STRUCT_PACKED #define STRUCT_PACKED #endif #ifndef STRUCT_UNPACKED #define STRUCT_UNPACKED __attribute__((__packed__)) #endif #elif defined(__CC_ARM) || (defined(__ARMCC_VERSION)) #ifndef STRUCT_PACKED #define STRUCT_PACKED _Pragma("pack(1U)") #endif #ifndef STRUCT_UNPACKED #define STRUCT_UNPACKED _Pragma("pack()") #endif #endif
Is the definition for __GNUC__ wrong? I expected STRUCT_PACKED to be __attribute__((__packed__)) instead of the other way around, i.e.
#ifndef STRUCT_PACKED #define STRUCT_PACKED __attribute__((__packed__)) #endif #ifndef STRUCT_UNPACKED #define STRUCT_UNPACKED #endif
Hi,
We don't have any issue regarding this, however, we will check it internally. Thank you for your feedback,
Regards
Soledad
Perhaps this only potentially becomes a problem when using different platforms or different toolchains in a project/system.
And affected users don't lament loud enough ...
That depends.
In my experience, "packed" structs are often used as overlays for serial data transfer (ethernet, Modbus, USB, CAN) and in data file interpretation.
In most cases, metadata are embedded in the byte stream, and interpreted via the "packed" overlay structure.
However, such projects usually included a manual check that the linker-generated struct offsets really matched the intended sizes/offsets.