comparison of unsigned expression >= 0 is always true

Write your question here.
Hello,
while compiling the below code, I get this strange ( to me ) warning.
warning: comparison of unsigned expression >= 0 is always true
1
2
3
4
5
6
7
  Put the code you need help with here.
 unsigned int myvalue = 3;
 if( ( my value >= 0 ) && ( myvalue <= 8 ) )
        { dosomething(); }
 but this works ok :
 if( ( my value ) && ( myvalue <= 8 ) )
        { dosomething(); }

TIA
mycuser
If myvalue is unsigned (so it can never be less than 0), then the test myvalue >= 0 will always be true, so it's pointless. You only need the myvalue <= 8 part. In the second piece of code, just writing myvalue is equivalent to writing myvalue != 0, which is obviously a different and potentially useful comparison.
Last edited on
It's a no-brainer. I forgot to think, but that's what you guys are here for : make us think. :)
But thanks,
Topic archived. No new replies allowed.