3 ms·
I believe the Bit Estimator example could be better: int test(unsigned char a) { short b = a; // b: 00000000________, a: ________ b <<= 4;
by zoren 10y ago
I believe the Bit Estimator example could be better:
int test(unsigned char a) {
short b = a; // b: 00000000________, a: ________
b <<= 4; // b: 0000________0000
b |= 3; // b: 0000________0011
return b != 0; // -> return true
}
The analyzer doesn't need any information about the two low bits of b to know b != 0. Had it been b ^= 3 instead of b |= 3, it would be a different matter.
- gratilup 10y agoI tried to have a simple example, maybe it was too simple. You are right, an OR with a constant is enough to know it is not zero. For this case the Bit Estimator also knows b = [3, 4083], writing something that takes advantage of this info would have been more interesting.