Click on image to see enlargment

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

            bug846.cpp

1    //lint -u   unit check
2
3    struct Hole {
4        int Fairway:1,
5        OutOfBounds:1,
6        Water:1,
7        Green:1;
8        /*etc*/
9        };
10   #define NHoles 18
11   Hole Holes[NHoles];
12
13   int Number_of_Fairways()
14       {
15       int nof = 0;
16       for( int i = 0; i < NHoles; i++ )
17           if( Holes[i].Fairway > 0 ) nof++;
18       return nof;
19       }

Dolph the golfer is preparing his own personal data base of golfing statistics. But after carefully preparing the data, to his chagrin, he found that he had not hit any fairways, though he could have sworn that he had. What's going wrong?


bug846.cpp lint Output

--- Module:   bug846.cpp (C++)
               _
    int Fairway:1,
bug846.cpp  4  Info 846: Signedness of bit-field is implementation defined
bug846.cpp  4  Info 806: Small bit field is signed rather than unsigned
               _
    OutOfBounds:1,
bug846.cpp  5  Info 846: Signedness of bit-field is implementation defined
bug846.cpp  5  Info 806: Small bit field is signed rather than unsigned
         _
    Water:1,
bug846.cpp  6  Info 846: Signedness of bit-field is implementation defined
bug846.cpp  6  Info 806: Small bit field is signed rather than unsigned
         _
    Green:1;
bug846.cpp  7  Info 846: Signedness of bit-field is implementation defined
bug846.cpp  7  Info 806: Small bit field is signed rather than unsigned
                                 _
        if( Holes[i].Fairway > 0 ) nof++;
bug846.cpp  17  Warning 685: Relational operator '>' always evaluates to 'false'

    --- Wrap-up for Module: bug846.cpp

Info 754: local structure member 'Hole::OutOfBounds' (line 5, file bug846.cpp) not referenced
Info 754: local structure member 'Hole::Water' (line 6, file bug846.cpp) not referenced
Info 754: local structure member 'Hole::Green' (line 7, file bug846.cpp) not referenced

Reference Manual Explanation


846    Signedness of bit-field is implementation defined  -- A bit-field was detected having the form:
                 int a:5;

       Most bit fields are more useful when they are unsigned.  If you want to have a signed bit field
       you must explicitly indicate this as follows:

                 signed int a:5;

       The same also holds for typedef's.  For example,

                 typedef int INT;
                 typedef signed int SINT;
                 struct  {
                         INT a:16;   // Info 846
                         SINT b:16;  // OK
                         }:

       It is very unusual in C or C++ to distinguish between signed int and just plain int.  This is one
       of those rare cases.


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


Previous Bug - Bug #452 - May 2012

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 2012, Gimpel Software, All rights reserved.