[previous] 3417 [next] The comma operator has been used outside a 'for' statement.
Arithmetic type - Operations

The comma operator is used to incorporate two statements into one, but it can often serve to confuse. Probably the most usual context in which it is used is in a "for" loop construct where two "loop control variables" are required. By using the comma operator it is possible to initialise both variables in the first expression and increment them both in the third.

(Be sure to distinguish the 'comma operator' from the 'comma punctuator'. The comma punctuator is used to separate arguments in an argument list, constants in an enumeration, a series of initializers etc.).

Use of the comma operator is identified by one of the following messages:

For example:


/*PRQA S 2017,3120,3198,3408,3440,3447 ++*/

extern int a;
extern int b;
extern int c;

extern void foo(void)
{
    int i;
    int j;

    a = b++, c++;                                       /* Message 3417 */

    b++;                                                /* Separate statements are clearer */
    a = c++;

    for (i = 0, j = 10; i < 10; ++i, ++j)               /* Message 3418 and 3418 */
    {
    }
}

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents