if say I have an int 12 and 200
and I cast both to u_char, as we all know the int value 12 is less than 200. What if I convert both to u_char, will the comparison of (u_char) 12 < (u_char) 200 always be true?
if say I have an int 12 and 200
and I cast both to u_char, as we all know the int value 12 is less than 200. What if I convert both to u_char, will the comparison of (u_char) 12 < (u_char) 200 always be true?
Yeah, that condition will always be true.
If you want to compare an int and a uchar, then something like this would work:
. . . since casting the int to a uchar is undesirable.Code:if((int)ucharvariable < intvariable) /* do stuff */
Do as I say, not as I do . . .
Experimentation is the essence of programming. Just remember to make a backup first.
"I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF
Questions posted by these guidelines are more likely to be answered.
Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.
hmm... if I cast an int to a u_char and cast it back to a u_char, I asked someone that I might not get the same result..
in other words it's impossible to get the original int value after casting it to an u_char, is this true?
Correct, unless the original int value was less than 256, in which case the data will be unchanged.
EDIT: assuming you mean "cast it back to an int", not a uchar.
Do as I say, not as I do . . .
Experimentation is the essence of programming. Just remember to make a backup first.
"I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF
Questions posted by these guidelines are more likely to be answered.
Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.