V2561. MISRA. The result of an assignment expression should not be used.

This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).

Using the assignment operation in subexpressions introduces an additional side effect making the code less readable and more susceptible to new mistakes.

Besides, following this rule significantly reduces the risk of confusing the operators '=' and '=='.

Example of non-compliant code:

int Inc(int i)
{
  return i += 1; // <=
}

void neg(int a, int b)
{
  int c = a = b; // <=

  Inc(a = 1);    // <=

  if(a = b) {}   // <=
}

This diagnostic is classified as:

  • MISRA-C-13.4
  • MISRA-CPP-6.2.1
  • AUTOSAR-M6.2.1

Bugs Found

Checked Projects
412
Collected Errors
14 132
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept