For the following program:
int main(void)
{
int value = 2;
int result = value >> 1U;
return result;
}
...Splint 3.1.2 gives the warning:
splint_test.c: (in function main)
splint_test.c:4:18: Variable result initialized to type unsigned int, expects
int: value >> 1U
To ignore signs in type comparisons use +ignoresigns
Splint seems to be claiming that an expression where a signed integer is shifted right has the type of an unsigned integer. However, all I can find in the ANSI C90 standard is:
The result of
E1 >> E2
isE1
right-shiftedE2
bit positions. IfE1
has an unsigned type or ifE1
has a signed type and a nonnegative value, the value of the result is the integral part of the quotient ofE1
divided by the quantity, 2 raised to the powerE2
.
The primary target for this code is an embedded system with a mostly-C90 compiler. However, I'm interested in writing standards-compliant code. I have been testing on GCC and Clang in C99 mode so that restrict
works.
My questions are:
- Does the C standard make any claims about the type of the result of a bit-shift?
- Do compilers?
- If not, why might Splint be issuing this warning?