Re: warning: comparison between signed and unsigned integer expressions
Paul Sargent <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Apr 20, 2010 at 23:14, Clark Cox <[email protected]> wrote: > On Tue, Apr 20, 2010 at 1:59 PM, Stephen Hoffman <[email protected]> wrote: >> Have a look around for the value-preserving and unsigned-preserving discussions; current C tends to be value-preserving. > > The value-preserving behavior is mandated by the C standard wherever possible. I feel I should know this, but I had to do a test to find what exactly you meant by "value-preserving". int a; unsigned int b; a = -1; b = (int) a; What is 'b'? As it turns out, it's 4294967295 or 0xFFFFFFFF BTW for the original poster, if all you're doing is equality comparisons (or not equal) a simple case tends to be fine, just be careful with < & >. -1 suddenly becomes greater than zero.