Click on image to see enlargment

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

            bug834.cpp

1    #include <stdio.h>
2
3    #define R(x) (1/x)  // R(x) yields the Reciprocal of x
4
5    int main( )
6        {
7        double westerly = 11.2;           // west wind component
8        double northerly = 5.6;           // north wind component
9        #define r northerly / westerly    // ratio of north to west winds
10
11       printf( "The ratio of north to west winds is %g\n", r );
12       printf( "The ratio of west to north winds is %g\n", R(r) );
13       return 0;
14       }

The weatherman is developing a new theory concerning the ratio of west to north wind components. But he is being confounded by the fact that although the ratio of north to west winds is 0.5, the ratio of west to north winds is complete garbage. What's the problem?


bug834.cpp lint Output

--- Module:   bug834.cpp
                                        _
    #define r northerly / westerly      // ratio of north to west winds
bug834.cpp(10) : Info 773: Expression-like macro 'r' not parenthesized
                                                           _
    printf( "The ratio of west to north winds is %g\n", R(r) );
bug834.cpp(13) : Warning 665: Unparenthesized parameter 1 in macro 'R' is
    passed an expression
bug834.cpp(13) : Info 834: Operator '/' followed by operator '/' is confusing.
    Use parentheses.

Reference Manual Explanation


834   Operator 'Name' followed by operator 'Name' is confusing.
      Use parentheses. -- Some combinations of operators seem to be confusing.
      For example:

                a = b - c - d;
                a = b - c + d;
                a = b / c / d;
                a = b / c * d;

      tend to befuddle the reader.  To reduce confusion we recommend using
      parentheses to make the association of these operators explicit.
      For example:

                a = (b - c) - d;
                a = (b - c) + d;
                a = (b / c) / d;
                a = (b / c) * d;

      in place of the above.

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

Previous Bug - Bug #1770 - February 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.