Reputation: 3287
I have the following code:
#define NUMBER_OF_ROOMS
if((unsigned int)(NUMBER_OF_ROOMS - 2) > 20)
{
// do something here
}
but I got a lint warning:Warning 506: Constant value Boolean
, what does this mean and how to fix it?
Upvotes: 1
Views: 2660
Reputation: 400029
It means that the value of the expression is constant, and thus the if
is pointless since it's known at compile-time whether or not it will be true or not.
You could of course make it more dynamic, or use the preprocessor instead:
#if (NUMBER_OF_ROOMS - 2) > 20
// do something here
#endif
I assumed the cast to (unsigned int)
was pointless, if these really were values close to the boundaries of the integer precision, then Jens Gustedt's comment applies.
Upvotes: 6
Reputation: 887867
It means that the value of your if
statement is known at compile-time.
The compiler just sees if (30 - 2 > 20)
(plus an unneeded cast), which it doesn't need to evaluate at runtime.
Upvotes: 3