Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
13.3 Should side effects be allowed in comma expressions?
#1
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;
    }
}
Reply
#2
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].
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)