USB SDK STRUCT_UNPACKED

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

USB SDK STRUCT_UNPACKED

2,223 次查看
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
标签 (2)
标记 (3)
0 项奖励
回复
6 回复数

2,155 次查看
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 项奖励
回复

1,907 次查看
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 项奖励
回复

1,887 次查看
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 项奖励
回复

1,884 次查看
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 项奖励
回复

1,881 次查看
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 项奖励
回复

1,879 次查看
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 项奖励
回复