msvcp60: Avoid signed-unsigned integer comparisons

Max TenEyck Woodbury max at mtew.isa-geek.net
Sun Mar 10 09:24:46 CDT 2013


On 03/10/2013 07:00 AM, Henri Verbeet wrote:
> On 10 March 2013 08:20, larmbr zhan <nasa4836 at gmail.com> wrote:
>>
>>     But It behaves different when it is signed or not.  According to
>>     C Standard,
 >>
>>     -  For the signed case, once it overflows, resulting in
>>        representing a  negative value .
>
> Actually, signed overflow behavior is undefined according to the
> standard.

Specifically, some hardware throws an exception on signed arithmetic
overflow and C is specifically designed to be hardware independent, so
it has to be 'undefined behavior'.

>>        -  For the unsigned case,  once it overflows, resulting in
>>           representing a value reduced modulo the largest value
>>           that object could hold.

Nit: modulo the largest value the object can hold _plus one_, but it 
should be treated as another 'undefined behavior'.

To further complicate the issue, while size_t is always unsigned, size_t 
can be 16, 18, 32, 36 or 64 bits and still be compliant.  So use
'size_t' when you are talking about the size of something, and
'unsigned' for flag sets and counts.



More information about the wine-devel mailing list