Over the last day, I had a nasty bug in my code that, after some searching, seems to be related to matching char and hex values. My gcc 4.4.1 compiler works on Windows. I reproduced the problem in the simple code below:
char c1 = 0xFF; char c2 = 0xFE; if(c1 == 0xFF && c2 == 0xFE) {
Surprisingly, the above code does not fall into the loop. I have absolutely no idea why and really will be very grateful for the help. This is so absurd that the decision should be (as always) a huge mistake on my part that I completely ignored.
If I replace the above with unsigned chars, this works, but only in some cases. I'm struggling to figure out what's going on. Also, if I compare hexadecimal values ββwith char, then it correctly enters a loop like this:
if(c1 == (char)0xFF && c2 == (char)0xFE) {
What does it mean? Why can this happen? Is the default value of raw hex interpreted as char? For a curious point in my code, where I first noticed, this is a comparison of the first 2 bytes of the stream with the specified hex value and their inverse to idenity byte order value.
Any help is appreciated
source share