I have the following code:
#define NUM_DAYS 65
#define NUM_PERSON 33
int num = 0;
if(NUM_DAYS % NUM_PERSON)
{
num = NUM_DAYS / NUM_PERSON;
}
else
{
uum = NUM_DAY / NUM_PERSON + 1;
}
num = num - 1;
while(num > 0)
{
//do something here
}
but I got the following lint warning:
Warning 681: Loop is not entered
what is the problem and how to fix it?
As your code is written, the loop will not be entered. NUM_DAYS % NUM_PERSON
will evaluate to true
, so num
will equal NUM_DAYS / NUM_PERSON
. Since we are dealing with ints, 65 / 33
is equal to 1
. 1 -1
is 0
, so the while condition will fail.
If your code is written as intended (as in, those constants are the values you are expecting to always use), just remove the while loop. It will never be used. If, however, NUM_DAYS
or NUM_PERSON
may later contain other values, you probably have nothing to worry about. If those specific values aren't important, try setting them to values such that the division will evaluate to something greater than 1
.
#define NUM_DAYS 65
#define NUM_PERSON 33
int num = 0;
if(NUM_DAYS % NUM_PERSON) // we go here, since (NUM_DAYS % NUM_PERSON) > 0
{
num = NUM_DAYS / NUM_PERSON; // so num = 1 now
}
else
{
uum = NUM_DAY / NUM_PERSON + 1;
}
num = num - 1; // num = 0 now
while(num > 0) // num = 0 ! So we don't go in this loop
{
//do something here
}
That's why you get this warning. The compiler has determined that your loop is useless (with your current #define
value).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With