PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page

            bug681.cpp

1     #include <stdio.h>
2
3     bool f( int n )
4         {
5         n = n + 1;
6         if( n < 10 ) return true;
7         else return false;
8         }
9
10    int main()
11        {
12        int n = 0;
13        int sum = 0;
14
15        while( f(n) && n ) sum += n;
16        printf( "%d\n", sum );
17        return 0;
18        }

Our programmer expected to sum the numbers from 1 to 9 but was disappointed when the value printed was something much less. What went wrong?


bug681.cpp lint Output

--- Module:   bug681.cpp
                     _
    while( f(n) && n ) sum += n;
bug681.cpp(15) : Warning 681: Loop is not entered

Reference Manual Explanation

 
681   Loop is not entered  -- The controlling expression for a
      loop (either the expression within a while clause or the
      second expression within a for clause) evaluates initially
      to 0 and so it appears as though the loop is never
      entered.

Previous Bug - Bug #568 - April 2002

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2003, Gimpel Software