USB SDK STRUCT_UNPACKED

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

USB SDK STRUCT_UNPACKED

2,183件の閲覧回数
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,115件の閲覧回数
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,867件の閲覧回数
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,847件の閲覧回数
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,844件の閲覧回数
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,841件の閲覧回数
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,839件の閲覧回数
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 件の賞賛
返信