Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top