Hello all,
I was working on a small ls program for a class assignment and we when trying to check if a character was greater than 127 or outside of the standard ascii bound it gcc gave me the error
condition is always false due to limited data type
with the code
This confused me because I was using an unsigned character type which means that I should have the values 0 - 255 to use instead of using the first bit as the sign bit. No matter what I did it always either failed or told me it would fail. Is there a reason for this?Code:usigned char token; fread(&token, 1, 1, file_desc); if(token > 127) /* this is where it gave me the error */ break;
Thank you!
note: I made this work by using a signed variable and checking if it was less than zero because any value that was greater than 128 up to 255 will have to have that bit set to one which would make an 8 bit 2's compliment number negative. But it is still very strange that it would not recognize the unsigned char values greater than 127...