Re: Comparing singed to unsinged warning



On Thu, 23 Aug 2007 01:09:39 +0200 (CEST), Nevil Lesdog <nl@xxxxxxxxx>
wrote:

What do you think is the best way to handle a compiler warning about
comparing an unsinged value to a singed value? Cast to silence it?
Disable that warning altogether? Or just live with it?

Look at the code and make darned sure you understand why the warning
occurred, and why it was necessary to compare things of two different
type. Then, if you still think it was the right thing to do, use a
cast, which will at least indicate that you did it on purpose.

On one hand, the warning *could* be useful. Most of the time I get it in
cases where I know the comparison is safe, but it's not hard to imagine
that this won't always be the case. This makes disabling it undesirable.
Casting is a workable solution, but I worry that changes in the code
later could introduce errors that go undetected due to the cast. And I
think we all hate not having a "clean" compile (if only because having a
bunch of warnings that you expected makes it more difficult to spot the
ones you didn't expect).

What is your opinion?

My opinion is that there's a very good chance that the code could be
better written.

--
Al Balmer
Sun City, AZ
.



Relevant Pages

  • warning - comparing a signed value to an unsinged value
    ... What do you think is the best way to handle a compiler warning about ... comparing an unsigned value to a signed value? ... This makes disabling it undesirable. ... later could introduce errors that go undetected due to the cast. ...
    (comp.lang.c)
  • Comparing singed to unsinged warning
    ... What do you think is the best way to handle a compiler warning about ... comparing an unsinged value to a singed value? ... This makes disabling it undesirable. ... later could introduce errors that go undetected due to the cast. ...
    (comp.lang.c)
  • Re: Comparing singed to unsinged warning
    ... comparing an unsinged value to a singed value? ... the warning *could* be useful. ... This makes disabling it undesirable. ... int CmpSU ...
    (comp.lang.c)
  • Re: function
    ... Now here's what I tried in error checking that gave me a warning. ... Without cast and comparing was mentioned by the compiler but it ...
    (comp.lang.c)
  • Re: [PATCH] [0/9] Use 64bit x86 machine check code for 32bit too
    ... warning: passing argument 2 of ‘strict_strtoull’ makes integer from pointer without a cast ...
    (Linux-Kernel)