Click on image to see enlargment

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

            bug440.cpp

1    #define NStu 3000
2    #define NCrs 400
3    extern int const StuCourse[NStu][NCrs];
4    extern double const CostBook[NCrs];
5    double total_cost()
6        {
7        int i, j;
8        double cost = 0;
9        for( i = 0; i < NStu; i++ )
10           for( j = 0; j < NCrs; i++ )
11               cost += StuCourse[i][j] *
12                       CostBook[j];
13       return cost;
14       }

The school bookstore is computing its annual budget. The array StuCourse indicates whether Student i is taking Course j and CostBook indicates the cost of the book for Course j. But something is going awry. Can you spot it?


bug440.cpp lint Output

--- Module:   bug440.cpp (C++)
                                  _
        for( j = 0; j < NCrs; i++ )
bug440.cpp  10  Warning 440: for clause irregularity: variable 'j' tested in
    2nd expression does not match 'i' modified in 3rd 
bug440.cpp  10  Warning 443: for clause irregularity: variable 'j' initialized
    in 1st expression does not match 'i' modified in 3rd
bug440.cpp  10  Warning 445: Reuse of for loop variable 'i' at 'line 9' could
    cause chaos
bug440.cpp  9  Info 830: Location cited in prior message
    _
    return cost;
bug440.cpp  13  Info 850: for loop index variable 'i' whose type category is
    'integral' is modified in body of the for loop that began at 'line 9'
bug440.cpp  9  Info 830: Location cited in prior message

Reference Manual Explanation


440 for clause irregularity: variable 'Symbol' tested in 2nd expression
    does not match 'Symbol' modified in 3rd -- A for clause has a suspicious
    structure. The loop variable, as determined by an examination of the
    3rd for clause expression, does not match the variable that is tested
    in the 2nd for clause expression. For example:
          for( i = 0; i < 10; j++ )
          ...
    would draw this complaint since the 'i' of the 2nd expression does not
    match the 'j' of the third expression.


If you have comments or questions about this bug, please post them to our   Discussion Forum


Previous Bug - Bug #578 - September 2008

Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2009, Gimpel Software, All rights reserved.