Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2004-12.10

In this section:
Synopsis

(Required) The comma operator shall not be used.

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

Uses of the comma operator were found. This check is identical to MISRAC++2008-5-18-1, MISRAC2012-Rule-12.3, MISRAC++2023-8.19.1.

Coding standards
MISRA C:2012 Rule-12.3

(Advisory) The comma operator should 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;
	}
}