Will such a comparison yield what I want (comparing the “low” byte of the int with the char)?
Which byte of the int will be compared with the char?
Will such a comparison yield what I want (comparing the “low” byte of the int with the char)?
Which byte of the int will be compared with the char?
[QUOTE=busketjoe;2005]Will such a comparison yield what I want (comparing the “low” byte of the int with the char)?
Which byte of the int will be compared with the char?[/quote]
In short: the least significant byte.
The char will (usually) be graduated to an int and then the 2 ints compared - but to be safe you may want to mask & cast :
int foo;
char bar;
if ( (char) (foo & 0xff) == bar )
return 1;
else
return 0;
In the course of graduation the sign of the char will be extended, so char 0x81 becomes int 0xff81. Have a care when mixing types (I usually use unsigned chars when I have to mix them up with other types to aleviate sign extension issues or having to cast as in the example above). I may be wrong and different compilers have their own flaws so it’s always best to worry about these things as you have done and have look at the object code produced to be sure!
Thanks.
That’s, roughly speaking, kind of what I gathered, but I’m a little bit shaky on the fundamentals.