I passed the following code through a static analysis tool:
u1 = (u1 ^ u2); // OK u1 = (u1 ^ u2) & u3; // NOT OK u1 = (u1 ^ u2) & 10; // NOT OK u1 = (u1 ^ u2) & 10U; // NOT OK u1 = (unsigned char)(u1 ^ u2) & 10U; // OK u1 = (unsigned char)(u1 ^ u2) & u3; // OK
βOKβ means the static analysis tool did not complain. "NOT OK" means that the static analysis tool complained - claiming that some operand of the bitwise operation is not an unsigned integer.
The results of the last two lines show that parentheses call either
but. actual type to signed conversion
b. what the static analysis tool considers to be a type to signed conversion
I will ask the developer of the static analysis tool about (b).
But before I do this, I would like to know if C (a) seems to be able to?
talkaboutquality
source share