MISRA Discussion Forums
Misra rule 42 - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forum-4.html)
+--- Forum: General Questions (https://forum.misra.org.uk/forum-27.html)
+--- Thread: Misra rule 42 (/thread-466.html)

Misra rule 42 - JeroenBoonen - 28-02-2008


I have a question concerning rule 42, which states : \"comma operator shall not be used, except in the control expression of a for loop\".

Now what is \"the control expression\" in following instruction : for(i = 0; i < 10; i++) {...}

Is it \"i = 0\" or \"i < 10\" or \"i++\" ?

Currently we use a GreenHills compiler with build-in misra checking and they are saying it is \"i < 10\".
Searching on google:
IAR and ABRAXAS says it is \"i = 0\" and \"i++\"

Now hopefully you can give me the correct answer.

Thank you,


Controlling expression - derek_farn - 28-02-2008

The technical term is actually \"controlling expression\", not \"control expression\".

The wording is here:

and the footnote specifying which of the expressions is the controlling expression (the middle one) is here

- JeroenBoonen - 28-02-2008

Hi, many thankx, so greenhills was right.

Anyway, where came this rule from? Because the comma operator is only usefull in the two other expressions, like:

for(i = 0,j = 0; i < 10; i++, j++)