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

            bug550.cpp

1     /* returns 100*bulls + cows where a bull is equality at some
2     index and a cow is equality at a different index.  a[] and b[]
3     are strings of length n.  Caution:  a and b are modified */
4
5     int Cows_Bulls( char a[], char b[], int n )
6         {
7         int i, j;
8         int cows = 0, bulls = 0, score = 0;
9
10        if( n >= 100 ) n = 99;
11        for( i = 0; i < n; i++ )
12            if( a[i] == b[i] )
13                { a[i] = 0; b[i] = 0; bulls++; score += 100; }
14        for( i = 0; i < n; i++ )
15            for( j = 0; j < n; j++ )
16                if( a[i] && a[i] == b[j] )
17                    { cows++; a[i] = 0; b[j] = 0; }
18        return score;
19        }

In this rendition of Cows and Bulls the function is to return a value of 100 times the number of bulls plus the number of cows. But it doesn't seem to be giving the right answer. What's the problem?


bug550.cpp lint Output

--- Module:   bug550.cpp
    _
    }
bug550.cpp  19  Warning 550: Symbol 'cows' (line 8) not accessed
bug550.cpp  19  Warning 550: Symbol 'bulls' (line 8) not accessed


Reference Manual Explanation

 
550    Symbol 'Symbol' (Location) not accessed  -- A variable (local to
       some function) was not accessed.  This means that the value of a
       variable was never used.  Perhaps the variable was assigned a
       value but was never used.  Note that a variable's value is not
       considered accessed by autoincrementing or autodecrementing
       unless the autoincrement/decrement appears within a larger
       expression which uses the resulting value.  The same applies to a
       construct of the form: var += expression.  If an address of a
       variable is taken, its value is assumed to be accessed. An array,
       struct or union is considered accessed if any portion thereof is
       accessed.


Previous Bug - Bug #542 - June 2001

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

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