PC-lint/FlexeLint Output |
Reference Manual Explanation |
1 #include <stdio.h>
3 #define R(x) (1/x) // R(x) yields the Reciprocal of x
5 int main( )
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
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;
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.
Reference Manual Explanation
834 Operator 'Name' followed by operator 'Name' is confusing.
Use parentheses. -- Some combinations of operators seem to be confusing.
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.
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