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

            bug542.cpp

1     #include <stdio.h>
2
3     struct { int bit:1; } s;
4
5     bool f()
6         {
7         if( s.bit > 0 ) return true;
8         else return false;
9         }
10
11    int main()
12        {
13        s.bit = 1;
14        if( f() ) printf( "the bit is ON\n" );
15        else printf( "the bit is OFF\n" );
16        return 0;
17        }

Why does this program say that the bit is OFF when we just turned it ON?


bug542.cpp lint Output

--- Module:   bug542.cpp
                  _
struct { int bit:1; } s;
bug542.cpp(4) : Info 806: Small bit field is signed rather than unsigned
             _
    s.bit = 1;
bug542.cpp(14) : Warning 542: Excessive size for bit field


Reference Manual Explanation

 
542    Excessive size for bit field  -- An attempt was made to assign a
       value into a bit field that appears to be too small.  The value
       to be assigned is either another bit field larger than the
       target, or a numeric value that is simply too large.  You may
       cast the value to the generic unsigned type to suppress the
       error.

       You may get this message unexpectedly if the base of the bit
       field is an int.  For example:

            struct { int b : 1 } s;
            s.b = 1;        /* Warning - - requires 0 or -1 */

       The solution in this case is to use 'unsigned' rather than 'int'
       in the declaration of b.


Previous Bug - Bug #1536 - May 2001

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

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