Click on image to see enlargment

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

            bug514.c

1    #include <stdio.h>
2
3    #define Raining 0x04
4
5    int bring_flowers( unsigned u )
6        {
7        if( u & Raining == 0 ) return 0;
8        else return 1;
9        }
10
11   int main()
12       {
13       printf( "%d\n", bring_flowers( 0x1B ) );
14       return 0;
15       }

Why does this C program print '1' rather than '0'?


bug514.c lint Output

--- Module:   bug514.c
                         _
    if( u & Raining == 0 ) return 0;
bug514.c(7) : Warning 514: Unusual use of a Boolean expression
bug514.c(7) : Info 774: Boolean within 'if' always evaluates to False
    [Reference: file bug514.c: line 7]

Reference Manual Explanation


514   Unusual use of a Boolean  -- An argument to an arithmetic
      operator (+ - / * %) or a bit-wise logical operator (| &
      ^) was a Boolean.  This can often happen by accident as in:

            if( flags & 4 == 0 )

      where the ==, having higher precedence than &, is done
      first (to the puzzlement of the programmer).

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

Previous Bug - Bug #834 - March 2005

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