Click on image to see enlargment

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

            bug666.c

1    #include <stdio.h>
2
3    char wingT[] = "O O O O O O       O"
4                   "      O            "
5                   "              O    "
6                   "    O   O          ";
7
8    #define Add(x,sum) ((x)==0 ? 0 : (x)==' ' ? 1 : ++(sum))
9
10   main()
11       {
12       int sum = 0;
13       int i=0;
14       while( Add( wingT[i++], sum ) )
15           /* keep looping */;
16       printf( "The number of players in the wingT "
17               "formation is %d\n", sum );
18       return sum;
19       }

The local college coach was using a C program to check the validity of his formations but he suspects something wrong when the player count shows 3 rather than the expected 11. What's going wrong?


bug666.c lint Output

--- Module:   bug666.c (C)
                                _
    while( Add( wingT[i++], sum ) )
bug666.c(14) : Warning 666: Expression with side effects passed to repeated
    parameter 1 in macro 'Add'

Reference Manual Explanation


666    Expression with side effects passed to repeated parameter Integer
       in macro 'Symbol'  -- A repeated parameter within a macro was
       passed an argument with side-effects.  For example:

             #define ABS(x) ((x) < 0 ? -(x) : (x))

             ... ABS( n++ )

       Although the ABS macro is correctly defined to specify the
       absolute value of its argument, the repeated use of the parameter
       x implies a repeated evaluation of the actual argument n++.  This
       results in two increments to the variable n.  [22, 20.6]  Any
       expression containing a function call is also considered to have
       side-effects.

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

Previous Bug - Bug #521 - September 2006

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