Home > Back-end >  Clang to Tidy the use of a signed integer operand with a binary bitwise operator
Clang to Tidy the use of a signed integer operand with a binary bitwise operator

Time:01-08



I use C on CLion implements a sequence table, at the time of expansion, I choose expansion for the original 1.5 times, as shown in figure code, I operated by displacement when the compiler will report a warning, warning the baidu, Google is to look not to understand, that also please the great god inspiration. Thank you!

CodePudding user response:

This warning is for a signed do a bitwise operations, the size should be symbolic variable, if will try unsigned variable size programming, a signed integer programming unsigned integer,

CodePudding user response:

reference 1st floor cfjtaishan response:
this warning is for a number of symbols do bitwise operations, the size should be a symbolic variable, if will try unsigned variable size programming, a signed integer programming unsigned integer,


Just tried to unsigned will also have this warning,, and I don't usually unsigned, calculation may have a problem with the words,,
Don't have C symbol digital shift will have a problem?

CodePudding user response:

refer to the second floor SinY_Chan response:
Quote: refer to 1st floor cfjtaishan response:

This warning is to have a number of symbols do bitwise operations, the size should be a symbolic variable, if will try unsigned variable size programming, a signed integer programming unsigned integer,


Just tried to unsigned will also have this warning,, and I don't usually unsigned, calculation may have a problem with the words,,
Don't have C symbol digital shift will have a problem?

The proposal does not use shift operation, and use division, namely p - & gt; The size/2 + 1;

CodePudding user response:

reference cfjtaishan reply: 3/f
Quote: refer to the second floor SinY_Chan response:

Quote: refer to 1st floor cfjtaishan response:

This warning is to have a number of symbols do bitwise operations, the size should be a symbolic variable, if will try unsigned variable size programming, a signed integer programming unsigned integer,


Just tried to unsigned will also have this warning,, and I don't usually unsigned, calculation may have a problem with the words,,
Don't have C symbol digital shift will have a problem?

The proposal does not use shift operation, and use division, namely p - & gt; The size/2 + 1;


Well? I'm into this kind of writing, because I think using displacement operation would be faster,, so just wrote, but feel nothing but give me warning, have questions, or thank you

CodePudding user response:

Fyi:
 # include & lt; stdio.h> 
Unsigned short int UI;
Signed short int si;
Int main () {
UI=(unsigned short int) 0 x8000u;
Si=(signed short int) 0 x8000;
Printf (" UI=% u \ n ", UI);
Printf (" si=% d \ n ", si);
UI=ui> 1;
Si=si> 1;
Printf (" UI=% u \ n ", UI);
Printf (" si=% d \ n ", si);

Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
UI=(unsigned short int) 0 x8000u;
Si=(signed short int) 0 x8000;
Printf (" UI=% u \ n ", UI);
Printf (" si=% d \ n ", si);
UI=((signed short int) UI) & gt;> 1;
Si=((unsigned short int) si) & gt;> 1;
Printf (" UI=% u \ n ", UI);
Printf (" si=% d \ n ", si);

return 0;
}
//UI=32768
//si=- 32768
//UI=16384
//si=- 16384
//-- -- -- -- -- -- -- -- -- -- -- -- -- --
//UI=32768
//si=- 32768
//UI=49152
//si=16384

CodePudding user response:

reference 4 floor SinY_Chan response:
Quote: reference cfjtaishan reply: 3/f

Quote: refer to the second floor SinY_Chan response:

Quote: refer to 1st floor cfjtaishan response:

This warning is to have a number of symbols do bitwise operations, the size should be a symbolic variable, if will try unsigned variable size programming, a signed integer programming unsigned integer,


Just tried to unsigned will also have this warning,, and I don't usually unsigned, calculation may have a problem with the words,,
Don't have C symbol digital shift will have a problem?

The proposal does not use shift operation, and use division, namely p - & gt; The size/2 + 1;


Well? I'm into this kind of writing, because I think using displacement operation would be faster,, so just wrote, but feel no problem give me a warning, have questions, or thank you

Can also casts the first shift again,
 (unsigned int) (p - & gt; The size) & gt;> 1 

CodePudding user response:

Clang - Tidy static checking more stringent, bit operation must use an unsigned number, including constant,
In pl - & gt; The size & gt;> 1, light pl - & gt; The size is unsigned weren't enough, one must also be,
So, to pl - & gt; The size & gt;> 1 u, there will be no warning,

CodePudding user response:

The size change to unsigned
P - & gt; The size & gt;> 1 u
So I can

CodePudding user response:

Dare to use clang apes, all has the qualification as a lawyer, a.
  • Related