J
Joe Van Dyk
What bad things could happen if I compare signed and unsigned integers?
(is that even valid C?)
Thanks,
Joe
(is that even valid C?)
Thanks,
Joe
Joe said:What bad things could happen if I compare signed and unsigned integers?
(is that even valid C?)
Joe said:What bad things could happen if I compare signed and unsigned integers?
(is that even valid C?)
Thanks,
Joe
Joe said:Besides nasal demons?
First, why would you mix signed and unsigned int values for comparison?
These are two different animals and generally shouldn't be compared.
But if you must, check the int for < 0. If negative, there's your answer
because unsigned is >= 0 by definition.
Now, if the int is positive, cast it to unsigned and do the comparison.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.