Pplyspace complain about conversion overflow: Conversion from int 32 to unsigned int 32. However everything I have it defined as unsigned. Is it something in ~ operator?
8 次查看(过去 30 天)
显示 更早的评论
typedef union _EXIPC_TRACK_T {
U16 U;
struct _EXIPC_XTRACK_T {
U16 ct_tm :8;
U16 ct_fm :4;
U16 ct_nt :4;
} X;
} EXIPC_TRACK_T;
auto EXIPC_TRACK_T au_track0, au_track1;
(*p_MsgGrp->p_d_trk_ds)[0] = (U16) (( au_track0.U) & 0xFFFFU);
(*p_MsgGrp->p_d_trk_ds)[1] = (U16) ((~au_track0.U) & 0xFFFFU);
[SL: edited to apply code formatting]
0 个评论
回答(1 个)
Alexandre De Barros
2017-11-2
Hello Ahmad,
It has something to do with the ~ operator indeed. This operator will not be performed on U16 but on the "int" type. There is an "integral promotion" taking place here.
You will find more information on integral promotion for example here: https://www.securecoding.cert.org/confluence/display/c/INT02-C.+Understand+integer+conversion+rules
If you want to get rid of the overflow, you can explicitely cast the U16 to unsigned int before doing the negation:
u = (U16) ((~(unsigned int)au_track0.U) & 0xFFFFU);
Best regards,
Alexandre
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bug Finder Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!