Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2561. MISRA. The result of an...
menu mobile close menu
Additional information
toggle menu Contents

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

Oct 15 2019

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-2012-13.4
  • MISRA-C-2023-13.4
  • MISRA-CPP-2008-6.2.1