AnsweredAssumed Answered

USB SDK STRUCT_UNPACKED

Question asked by Rex Lam on Jun 10, 2019
Latest reply on Jun 24, 2019 by soledad

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

Outcomes