MISRA Discussion Forums
13.3 Should side effects be allowed in comma expressions? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.13 Side effects (https://forum.misra.org.uk/forumdisplay.php?fid=168)
+---- Thread: 13.3 Should side effects be allowed in comma expressions? (/showthread.php?tid=1781)



13.3 Should side effects be allowed in comma expressions? - Loïc - 31-08-2026

In a comma expression (which is discouraged by another advisory rule, 12.3, but could still be used), there is a clear separation in term of execution between what comes before and what comes after the comma. Therefore, I think the rationale is not very strong in this case.

What would you think of relaxing 13.3 and making this example compliant (it would still be non-compliant with 12.3):

Code:
int f(int n, int*dest) {
    for (int i = 0 ; i<10 ; ++i, ++dest) { // Currently non-compliant
        *dest = i*i;
    }
}



RE: 13.3 Should side effects be allowed in comma expressions? - misra-c - 08-10-2026

The example also violates Rule 14.2 - the third term can only modify the loop counter

The MISRA C WG agrees that this is an unnecessary violation of Rule 13.3, and will consider refinement [ID: 481 applies].