Click on image to see enlargment

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

            bug681.cpp

1    #include <stdio.h>
2    #define FIRST_YEAR 1901
3    #define LAST_YEAR 2006
4    #define NSTATIONS 100
5    extern double
6        temperatures[LAST_YEAR+1-FIRST_YEAR][NSTATIONS];
7
8    void print_temperatures()
9        {
10       double total;
11
12       for( int i = LAST_YEAR; i <= FIRST_YEAR; i-- )
13           {
14           total = 0.0;
15           for( int j = 0; j < NSTATIONS; j++ )
16               total += temperatures[i-FIRST_YEAR][j];
17           printf( "Ave. temp. for year %d is %g\n",
18               i, total / NSTATIONS );
19           }
20       }

In an effort to examine evidence of global warming (or cooling) the programmer wrote this function but the results were quite unexpected. What's going wrong?


bug681.cpp lint Output

--- Module:   bug681.cpp (C++)
                                 _
    for( int i = LAST_YEAR; i <= FIRST_YEAR; i-- )
bug681.cpp(12) : 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.

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

Previous Bug - Bug #428 - July 2006

[ new ] 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 2006, Gimpel Software, All rights reserved.