Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Questions about Rule 2.1
#2
The default statement in the example of rule 2.1 may or may not be reachable depending on other code.

For instance:
1. If the value of the "enum light" argument is always one of the enumeration's constants, then the default statement is unreachable and the line is not compliant with this rule.

2. If the value of the "enum light" argument can have a value less than 0 or greater than 3, then the default statement can be reached and the line is compliant with this rule.

For this reason, Rule 2.1 is marked as "Undecidable", which means that it is not possible to construct a general algorithm that gives a "compliant" / "not compliant" answer for every possible program that may use the "next_light" function.

For a particular instance of a program, an analysis tool may be able to determine whether the statement is reachable or not and give a message if appropriate. However, there will be cases where analysis tools can not determine the outcome. Section 6.5 of the MISRA C:2012 guidelines discuss the decidability of rules and how static analysers may differ in the reporting of undecidable rules.
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)