Click on image to see enlargment

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


1    #include <stdio.h>
2    #define Hot_Dog 1
3    #define Potato_Salad 2
4    #define Green_Salad 4
5    #define Hummus_Sandwich 8
6    unsigned Grand_Menu = 0x70E;
7    unsigned select(int v)      // v means vegetarian
8        {
9        return (Grand_Menu >> !v ? 8 : 0) & 0xFF;
10       }
11   int main()
12       {
13       printf( "%x\n", select(0) );
14       }

Will is preparing a 4th of July barbeque and is employing his new found programming skills to help prepare the menu. However, the value printed indicates that the meat eaters will be served a hummus sandwich. What's going on?

bug504.c lint Output

--- Module:   bug504.c (C)
    return (Grand_Menu >> !v ? 8 : 0) & 0xFF;
bug504.c(9) : Warning 504: Unusual shift operation (unusually formed right argument)
bug504.c(9) : Warning 514: Unusual use of a Boolean expression

    --- Wrap-up for Module: bug504.c

Info 750: local macro 'Hot_Dog' (line 2, file bug504.c) not referenced
Info 750: local macro 'Potato_Salad' (line 3, file bug504.c) not referenced
Info 750: local macro 'Green_Salad' (line 4, file bug504.c) not referenced
Info 750: local macro 'Hummus_Sandwich' (line 5, file bug504.c) not referenced

Reference Manual Explanation

504    Unusual shift operation (String) -- Either the quantity being shifted or the
       amount by which a quantity is to be shifted was derived in an unusual way such
       as with a bit-wise logical operator, a negation, or with an unparenthesized
       expression.  If the shift value is a compound expression that is not parenthesized,
       parenthesize it.

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

Previous Bug - Bug #553 - June 2008

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.