MISRAC2012-Rule-12.3
In this section:
Synopsis
(Advisory) The comma operator should not be used
Enabled by default
No
Severity/Certainty
Low/High

Full description
There are uses of the comma operator. This check is identical to MISRAC2004-12.10, MISRAC++2008-5-18-1, MISRAC++2023-8.19.1.
Coding standards
- MISRA C:2004 12.10
(Required) The comma operator shall not be used.
- MISRA C++ 2008 5-18-1
(Required) The comma operator shall not be used.
- MISRA C++ 2023 8.19.1
(Advisory) The comma operator should not be used
Code examples
The following code example fails the check and will give a warning:
#include <string.h>
void reverse(char *string) {
int i, j;
j = strlen(string);
for (i = 0; i < j; i++, j--) {
char temp = string[i];
string[i] = string[j];
string[j] = temp;
}
}
The following code example passes the check and will not give a warning about this issue:
#include <string.h>
void reverse(char *string) {
int i;
int length = strlen(string);
int half_length = length / 2;
for (i = 0; i < half_length; i++) {
int opposite = length - i;
char temp = string[i];
string[i] = string[opposite];
string[opposite] = temp;
}
}