USB SDK STRUCT_UNPACKED

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB SDK STRUCT_UNPACKED

947 Views
rex_lam
Contributor IV

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
Labels (2)
Tags (3)
0 Kudos
6 Replies

879 Views
soledad
NXP Employee
NXP Employee

Hi, 

We don't have any issue regarding this, however, we will check it internally. Thank you for your feedback,

Regards 

Soledad

0 Kudos

631 Views
HSL_AB
Contributor I
Years pass - and SDK_2_11_1_MIMXRT1052xxxxB pack still contains this old described error in the "usb_misc.h" file. What is your reason?
0 Kudos

611 Views
frank_m
Senior Contributor III

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 ...

0 Kudos

608 Views
HSL_AB
Contributor I
While STRUCT_UNPACKED is not used in SDK there is no problem: let assume that nobody will use this #define deliberately
0 Kudos

605 Views
frank_m
Senior Contributor III

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.

0 Kudos

603 Views
HSL_AB
Contributor I
Obviously, "packed" does be widely used, but I assume that little people know about the existence of this particular #define. I hadn't known before.
0 Kudos