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?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Alexandre De Barros
am 2 Nov. 2017
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 Kommentare
Siehe auch
Kategorien
Mehr zu Bug Finder Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!