On 10/04/2013, at 11:06 AM, Nico Williams <n...@cryptonector.com> wrote:

> On Mon, Apr 8, 2013 at 8:52 AM, Alexandr Němec <a.ne...@atlas.cz> wrote:
>>> The first warning is harmless and results from a prior datatype change.
>>> Dan has already fixed that one.  The other four appear to be due to an
>>> MSVC compiler bug, since every (i64%int) operation will always yield a value
>>> that can fit in an int, no?
>> 
>> Ok, thank for this comment. Of course, you are right, although I wouldn't
>> call it a compiler bug. The (i64%int) operation, gives an int result, but
>> allocated into an i64 value, so this is why the compiler reports the
>> warning. But thanks, it is obvious now, that these warnings can be ignored.
> 
> The compiler is complaining about an int64->int conversion, not the reverse.
> 
> Why on Earth would going from an int (64-bit or smaller) to an int64
> cause a problem?
> 
> No, this is a compiler bug.

It is not a compiler bug. It is a failure of the compiler to deduce that the 
warning is unnecessary.

One of the lines in question is:

Line 71133     iBuf = p->iReadOff % p->nBuffer;

iBuf is an int.

p->iReadOff is an i64.

p->nBuffer is an int.

C's usual arithmetic conversions specify that if either operand of a binary 
operator is an integer type larger than int then the other operand is first 
converted to the larger type. Therefore p->nBuffer is converted from int to i64 
before doing the modulo operation.

We now have i64 % i64, producing a result of type i64.

The statement then stores that i64 result into an int. i64 conversion to int 
without a cast produces the warning in MSVC (if int is 32-bit).

If the compiler was smarter, it would pay attention to the fact that the 
modulus cannot exceed the range of an int, therefore the warning is not 
necessary.

The only reason I can see not to have an explicit cast is that it risks hiding 
a future bug if the types of the variables are changed.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to