Misra rule 42

Questions and discussions about MISRA C not fitting under migration or rules forums

Moderators: misra-c, david ward

Post Reply
JeroenBoonen
Posts: 2
Joined: Mon Feb 25, 2008 4:56 pm
Location: Belgium

Misra rule 42

Post by JeroenBoonen » Thu Feb 28, 2008 9:45 am

Hi,

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,

Jeroen

derek_farn
Posts: 12
Joined: Tue Sep 28, 2004 11:40 am
Company: Knowledge Software
Location: SW London
Contact:

Controlling expression

Post by derek_farn » Thu Feb 28, 2008 1:12 pm

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

The wording is here:
http://c0x.coding-guidelines.com/6.8.5.3.html

and the footnote specifying which of the expressions is the controlling expression (the middle one) is here
http://c0x.coding-guidelines.com/6.8.6.html
Applications conformance testing: http://www.knosof.co.uk/cbook

JeroenBoonen
Posts: 2
Joined: Mon Feb 25, 2008 4:56 pm
Location: Belgium

Post by JeroenBoonen » Thu Feb 28, 2008 1:26 pm

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++)

Greetings,

Jeroen

Post Reply

Return to “General Questions”