unless x is an integer larger than 1/2 UINT_MAX... then it's still a bad test.

it's safer to test if the signed is less than 0 otherwise cast that to
unsigned.


On Sun, Sep 26, 2010 at 10:06 PM, foxmuldrs...@yahoo.com
<foxmuldrs...@yahoo.com> wrote:
> Use the explicit override if you need signed comparison.
>
> unsigned int x;
> int y;
> if ((int)x < y)
>
> -Rick
>
> -----Original message-----
>
> From: J Decker <d3c...@gmail.com>
> To: Ian Lance Taylor <i...@google.com>
> Cc: gcc@gcc.gnu.org
> Sent: Mon, Sep 27, 2010 05:51:56 GMT+00:00
> Subject: Re: signed/unsigned comparison warning level
>
>> The standards did not leave this open.  They define precisely what is
>> supposed to happen.
>>
> Really? I'll have to drop this whole lobbying effort then. That
> makes me sad that they didn't define it to be comparing of the numbers
> where there are overlaps in signed and unsigned instead of causing all
> negative signed values to be wrong.
>
>>
>>> But if it's not fixed, this warning should definatly be issued at
>>> default warning level.  This should be more like 'if this comparison
>>> can be wrong, it will be wrong'.
>>
>> There is no problem comparing values of signed type with values of
>> unsigned type if the signed values are known to be nonnegative.  Of
>> course it is sometimes hard to know that; hence the warning.  But
>> enabling the warning by default does not make sense.
>>
>
> It's exactly the fact that 'of course it is sometimes....' that makes
> the warning make more sense to be on by default. I don't always know
> that I've added an unsigned value to an expression, causing one side
> of a comparison to become unsigned, resulting in 100% failure on
> negative signed result comparison.
>
>
>> Ian
>>
>

Reply via email to