Click on image to see enlargment

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

            bug564.cpp

1    #include <iostream.h>
2
3    const char *action[] = {
4        "sleigh to roof",
5        "descend chimney",
6        "fill stockings" };
7
8    void out( int n )
9        { cout << action[n] << "\n"; }
10
11   void santa_do( int a, int b, int c )
12       { out( a ); out( b ); out( c ); }
13
14   int main()
15       {
16       int i = 0;
17       santa_do( i++, i++, i++ );
18       return 0;
19       }

Santa and his elves are automating their Christmas delivery system. But one of the elves has made a critical error causing, in some areas, the actions to appear in an unexpected order. Can you find the problem? (Thanks to Frank Fosse for submtting the basic idea).


bug564.cpp lint Output

--- Module:   bug564.cpp (C++)
                      _
    santa_do( i++, i++, i++ );
bug564.cpp(17) : Warning 564: variable 'i' depends on order of evaluation
bug564.cpp(17) : Warning 564: variable 'i' depends on order of evaluation

Reference Manual Explanation


564    variable 'Symbol'  depends on order of evaluation  -- The named variable was
       both modified and accessed in the same expression in such a way that the result
       depends on whether the order of evaluation is left-to-right or right-to-left.
       One such example is:  n + n++ since there is no guarantee that the first access to n
       occurs before the increment of n.  Other, more typical cases, are given in the manual.
       Volatile variables are also checked for repeated use in an expression.




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


Previous Bug - Bug #443 - November 2011

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 2011, Gimpel Software, All rights reserved.