Reputation: 13
Is there any way to use two unsigned ints in an if statement a a signed int?
unsigned int a = 0, b = 1;
if (a - b > - 1)
++a;
Upvotes: 1
Views: 129
Reputation: 477358
How about:
if (a + 1 > b) {
++a;
}
(You may need to check for and deal wrap-around, i.e. the case where a + 1 == 0
, if your values are completely unconstrained.)
Or even (thanks to @M.M.):
if (a >= b) {
++a;
}
Upvotes: 3