![]() |
![]() |
3417 | ![]() |
||||
![]() | |||||||
| 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:
/*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 */
{
}
}
MISRA C:2012 Rules applicable to message 3417:
| Rule-12.3 (Advisory) | The comma operator should not be used |
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |