Click on image to see enlargment

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


1    #include <stdio.h>
3    // Oh, tis noble to count the shamrocks
4    int shamrock_count( int leaves, double leavesPerShamrock )
5        {
6        // you first start out with the number of petals
7        // that can be viewed from the hill at high noon.
8        double shamrocks = leaves;
9        // and then you apply the ancient Druid formula
10       shamrocks /= leavesPerShamrock;
11       // and then return from which we came.
12       return leaves;
13       }
15   int main()
16       {
17       printf( "%d\n", shamrock_count( 314159, 3.14159 ) );
18       return 0;
19       }

An elderly leprechaun, with an uncanny ability to count shamrock leaves, but with waining programming skills, wanted to determine the number of shamrocks in a field. His ancient forebears had determined the average number of leaves per shamrock. But his program seems to be failing him. What's going wrong?

bug438.cpp lint Output

--- Module:   bug438.cpp (C++)
    return leaves;
bug438.cpp(12) : Warning 438: Last value assigned to variable 'shamrocks'
    (defined at line 8) not used
bug438.cpp(13) : Warning 550: Symbol 'shamrocks' (line 8) not accessed

Reference Manual Explanation

438    Last value assigned to variable 'Symbol' not used  -- A value had
       been assigned to a variable that was not subsequently used.  The
       message is issued either at a return statement or at the end of a
       block when the variable goes out of scope.  For example, consider
       the following function:

                 void f( int n )
                     int x = 0, y = 1;
                     if( n > 0 )
                         int z;
                         z = x + y;
                         if( n > z ) { x = 3; return; }
                         z = 12;

       Here we can report that x was assigned a value that had not been
       used by the time the return statement had been encountered.  We
       also report that the most recently assigned value to z is unused
       at the point that z goes out of scope.  See message 838 in
       Section 13.4 C Informational Messages and flags -fiw and -fiz in
       Sections 2.3.6 Initialization-is-considered-a-Write flag (-fiw)
       and 2.3.7 Initialization-by-Zero-is-considered-a-Write flag

       This message is suppressed if the variable's address is assigned
       to a pointer (or, equivalently, the variable is used to directly
       initialize a reference to non-const).

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

Previous Bug - Bug #587 - February 2009

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.