Click on image to see enlargment

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

            bug806.cpp

1    #include <stdio.h>
2
3     struct pumpkin { int nose:1, eyes:2; } p = { 1, 2 };
4
5     int f()
6         {
7         if( p.nose > 0 && p.eyes > 1 ) return 1;
8         else return 0;
9         }
10
11    int main()
12        {
13        if( f() ) printf( "nose and eyes\n" );
14        else printf( "malformed\n" );
15        return 0;
16        }

The pumpkin producers wanted a nose and two eyes but this quality assurance program keeps printing 'malformed'. What's the problem?


bug806.cpp lint Output

--- Module:   bug806.cpp
                           _
struct pumpkin { int nose:1, eyes:2; } p = { 1, 2 };
bug806.cpp(3) : Info 806: Small bit field is signed rather than unsigned
bug806.cpp(3) : Info 806: Small bit field is signed rather than unsigned
bug806.cpp(3) : Warning 542: Excessive size for bit field
bug806.cpp(3) : Warning 542: Excessive size for bit field
                   _
    if( p.nose > 0 && p.eyes > 1 ) return 1;
bug806.cpp(7) : Warning 685: Relational operator '>' always evaluates to 'false'
bug806.cpp(7) : Warning 685: Relational operator '>' always evaluates to 'false'

Reference Manual Explanation

 
806   Small bit field is signed rather than unsigned  -- A small bit field 
      (less than an int wide) was found and the base type is signed rather 
      than unsigned.  Since the most significant bit is a sign bit this 
      practice can produce surprising results.  For example,

             struct { int b:1; } s;
             s.b = 1;
             if( s.b > 0 ) /* should succeed but actually fails */
             ...

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

Previous Bug - Bug #785 - September 2004

[ 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.