I have one WORD variable in my program.
WORD hour;
But when I compare It
if(hour>=0 && hour<=18)
{
hour+=6;
}
It will generate warning
[Warning] comparison is always true due to limited range of data type
I am using Dev-C++ as IDE.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the warning is for the comparison
hour >=0which is always true forhouris of typeWORDwhich is a typedef ofunsigned short(usually) which meanshouris always greater than or equal to0:On MSVC++ it is how WORD is defined, check your compiler if it is
unsignedor not. If itunsigned1, thenhour >=0is obviouslytruefor all possible values ofhour. In that case, you need to write just this:1. Note that it doesn’t matter whether is
unsigned intorunsigned short. As long as it isunsigned,hour >=0will be true for all possible values ofhour.