Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Application of rule 14.10 for Autogenerated code
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:

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 “
if ... else { if { ... } }
” construct and very close to the “
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?
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.

Forum Jump:

Users browsing this thread: 1 Guest(s)