MISRA Discussion Forums
Application of rule 14.10 for Autogenerated code - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA Autocode (https://forum.misra.org.uk/forumdisplay.php?fid=8)
+--- Forum: MISRA AC AGC discussions (https://forum.misra.org.uk/forumdisplay.php?fid=119)
+--- Thread: Application of rule 14.10 for Autogenerated code (/showthread.php?tid=934)



Application of rule 14.10 for Autogenerated code - ssauvage - 14-01-2013

I have recently received a question from a customer using our code generation tools (embedded coder).
The code that we generate for a block (saturate block) is like this:

Code:
rtB_out = something;
if(rtB_out > maxlim) {
   rtB_out = maxlim;
}
else {
   if(rtB_out < minlim) {
      rtB_out = minlim;
   }
}

The customer asked whether the code above was MISRA compliant, in particular with respect to rule 14.10.
It is an “
Code:
if ... else { if { ... } }
” construct and very close to the “
Code:
if ... else if ...
” construct as described in the rule 14.10.
However, it can be read as a simple if being the statement in an else clause.

Personally, I find the code quite readable as it is and it is easy to check that there is no path where rtB_out is not assigned a value.
Would you recommend to have a final else in this context?


Re: Application of rule 14.10 for Autogenerated code - MISRA Reply - 21-01-2013

The code sample complies with 14.10 as the second if is nested within a compound statement. We would not recommend a final else in this context and would suggest that the code has been laid out in this manner by the autocode generator specifically to abide by Rule 14.10 and thus avoid the use of an empty else { ... } clause, the only reasonable alternative if a further final else clause were included.